diff options
Diffstat (limited to 'tests/auto/corelib')
5 files changed, 138 insertions, 42 deletions
diff --git a/tests/auto/corelib/itemmodels/qconcatenatetablesproxymodel/tst_qconcatenatetablesproxymodel.cpp b/tests/auto/corelib/itemmodels/qconcatenatetablesproxymodel/tst_qconcatenatetablesproxymodel.cpp index 40617c1f7d..e1ea7a4552 100644 --- a/tests/auto/corelib/itemmodels/qconcatenatetablesproxymodel/tst_qconcatenatetablesproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qconcatenatetablesproxymodel/tst_qconcatenatetablesproxymodel.cpp @@ -116,6 +116,7 @@ private Q_SLOTS: void shouldPropagateDropBetweenItemsAtModelBoundary(); void shouldPropagateDropAfterLastRow_data(); void shouldPropagateDropAfterLastRow(); + void qtbug91788(); private: QStandardItemModel mod; @@ -453,6 +454,17 @@ void tst_QConcatenateTablesProxyModel::shouldUseSmallestColumnCount() const QModelIndex indexD = pm.mapFromSource(mod2.index(0, 0)); QVERIFY(indexD.isValid()); QCOMPARE(indexD, pm.index(1, 0)); + + // Test setData in an ignored column (QTBUG-91253) + QSignalSpy dataChangedSpy(&pm, SIGNAL(dataChanged(QModelIndex,QModelIndex))); + mod.setData(mod.index(0, 1), "b"); + QCOMPARE(dataChangedSpy.count(), 0); + + // Test dataChanged across all columns, some visible, some ignored + mod.dataChanged(mod.index(0, 0), mod.index(0, 2)); + QCOMPARE(dataChangedSpy.count(), 1); + QCOMPARE(dataChangedSpy.at(0).at(0).toModelIndex(), pm.index(0, 0)); + QCOMPARE(dataChangedSpy.at(0).at(1).toModelIndex(), pm.index(0, 0)); } void tst_QConcatenateTablesProxyModel::shouldIncreaseColumnCountWhenRemovingFirstModel() @@ -818,6 +830,19 @@ void tst_QConcatenateTablesProxyModel::shouldPropagateDropAfterLastRow() } +void tst_QConcatenateTablesProxyModel::qtbug91788() +{ + QConcatenateTablesProxyModel proxyConcat; + QStringList strList{QString("one"),QString("two")}; + QStringListModel strListModelA(strList); + QSortFilterProxyModel proxyFilter; + proxyFilter.setSourceModel(&proxyConcat); + + proxyConcat.addSourceModel(&strListModelA); + proxyConcat.removeSourceModel(&strListModelA); // This should not assert + QCOMPARE(proxyConcat.columnCount(), 0); +} + QTEST_GUILESS_MAIN(tst_QConcatenateTablesProxyModel) #include "tst_qconcatenatetablesproxymodel.moc" diff --git a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp index 7aadd14466..ce03487496 100644 --- a/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp +++ b/tests/auto/corelib/kernel/qeventdispatcher/tst_qeventdispatcher.cpp @@ -69,6 +69,7 @@ private slots: void processEventsOnlySendsQueuedEvents(); void postedEventsPingPong(); void eventLoopExit(); + void interruptTrampling(); }; bool tst_QEventDispatcher::event(QEvent *e) @@ -419,5 +420,31 @@ void tst_QEventDispatcher::eventLoopExit() QVERIFY(!timeoutObserved); } +// Based on QTBUG-91539: In the event dispatcher on Windows we overwrite the +// interrupt once we start processing events (this pattern is also in the 'unix' dispatcher) +// which would lead the dispatcher to accidentally ignore certain interrupts and, +// as in the bug report, would not quit, leaving the thread alive and running. +void tst_QEventDispatcher::interruptTrampling() +{ + class WorkerThread : public QThread + { + void run() override { + auto dispatcher = eventDispatcher(); + QVERIFY(dispatcher); + dispatcher->processEvents(QEventLoop::AllEvents); + QTimer::singleShot(0, [dispatcher]() { + dispatcher->wakeUp(); + }); + dispatcher->processEvents(QEventLoop::WaitForMoreEvents); + dispatcher->interrupt(); + dispatcher->processEvents(QEventLoop::WaitForMoreEvents); + } + }; + WorkerThread thread; + thread.start(); + QVERIFY(thread.wait(1000)); + QVERIFY(thread.isFinished()); +} + QTEST_MAIN(tst_QEventDispatcher) #include "tst_qeventdispatcher.moc" diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp index 274bf4f6f0..f94f1c5fa6 100644 --- a/tests/auto/corelib/time/qdate/tst_qdate.cpp +++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp @@ -90,7 +90,6 @@ private slots: void yearsZeroToNinetyNine(); void printNegativeYear_data() const; void printNegativeYear() const; - void roundtripGermanLocale() const; #if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) void shortDayName() const; void standaloneShortDayName() const; @@ -100,6 +99,7 @@ private slots: void standaloneShortMonthName() const; void longMonthName() const; void standaloneLongMonthName() const; + void roundtripString() const; #endif // textdate void roundtrip() const; void qdebug() const; @@ -1484,16 +1484,6 @@ void tst_QDate::printNegativeYear() const QCOMPARE(date.toString(QLatin1String("yyyy")), expect); } -void tst_QDate::roundtripGermanLocale() const -{ - /* This code path should not result in warnings. */ - const QDate theDate(QDate::currentDate()); - theDate.fromString(theDate.toString(Qt::TextDate), Qt::TextDate); - - const QDateTime theDateTime(QDateTime::currentDateTime()); - theDateTime.fromString(theDateTime.toString(Qt::TextDate), Qt::TextDate); -} - #if QT_CONFIG(textdate) && QT_DEPRECATED_SINCE(5, 10) QT_WARNING_PUSH // the methods tested here are all deprecated QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") @@ -1626,6 +1616,17 @@ void tst_QDate::standaloneLongMonthName() const } } QT_WARNING_POP + +void tst_QDate::roundtripString() const +{ + /* This code path should not result in warnings, no matter what locale is set. */ + const QDate date(QDate::currentDate()); + QCOMPARE(date.fromString(date.toString(Qt::TextDate), Qt::TextDate), date); + + const QDateTime now(QDateTime::currentDateTime()); + const QDateTime when = now.addMSecs(-now.time().msec()); // TextDate rounds to whole seconds. + QCOMPARE(when.fromString(when.toString(Qt::TextDate), Qt::TextDate), when); +} #endif // textdate void tst_QDate::roundtrip() const diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 2a8c47a51f..d3afee96cd 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -152,6 +152,7 @@ private slots: void isDaylightTime() const; void daylightTransitions() const; void timeZones() const; + void systemTimeZoneChange_data() const; void systemTimeZoneChange() const; void invalid_data() const; @@ -825,7 +826,7 @@ void tst_QDateTime::toString_isoDate_data() QTest::newRow("negative non-integral OffsetFromUTC") << dt << Qt::ISODate << QString("1978-11-09T13:28:34-00:15"); - QTest::newRow("invalid") + QTest::newRow("invalid") // ISODate < 2019 doesn't allow -ve year numbers; QTBUG-91070 << QDateTime(QDate(-1, 11, 9), QTime(13, 28, 34), Qt::UTC) << Qt::ISODate << QString(); QTest::newRow("without-ms") @@ -838,30 +839,31 @@ void tst_QDateTime::toString_isoDate_data() void tst_QDateTime::toString_isoDate() { - QFETCH(QDateTime, datetime); - QFETCH(Qt::DateFormat, format); - QFETCH(QString, expected); + QFETCH(const QDateTime, datetime); + QFETCH(const Qt::DateFormat, format); + QFETCH(const QString, expected); #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QLocale oldLocale; QLocale::setDefault(QLocale("en_US")); #endif // ### Qt 6: remove - QString result = datetime.toString(format); + const QString result = datetime.toString(format); QCOMPARE(result, expected); - QDateTime resultDatetime = QDateTime::fromString(result, format); - // If expecting invalid result the datetime may still be valid, i.e. year < 0 or > 9999 - if (!expected.isEmpty()) { - QEXPECT_FAIL("without-ms", "Qt::ISODate truncates milliseconds (QTBUG-56552)", Abort); - - QCOMPARE(resultDatetime, datetime); - QCOMPARE(resultDatetime.date(), datetime.date()); - QCOMPARE(resultDatetime.time(), datetime.time()); - QCOMPARE(resultDatetime.timeSpec(), datetime.timeSpec()); - QCOMPARE(resultDatetime.offsetFromUtc(), datetime.offsetFromUtc()); - } else { + const QDateTime resultDatetime = QDateTime::fromString(result, format); + if (QByteArray(QTest::currentDataTag()) == "invalid") { QCOMPARE(resultDatetime, QDateTime()); + } else { + const QDateTime when = + QByteArray(QTest::currentDataTag()) == "without-ms" + ? datetime.addMSecs(-datetime.time().msec()) : datetime; + QCOMPARE(resultDatetime.toMSecsSinceEpoch(), when.toMSecsSinceEpoch()); + QCOMPARE(resultDatetime, when); + QCOMPARE(resultDatetime.date(), when.date()); + QCOMPARE(resultDatetime.time(), when.time()); + QCOMPARE(resultDatetime.timeSpec(), when.timeSpec()); + QCOMPARE(resultDatetime.offsetFromUtc(), when.offsetFromUtc()); } #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -3721,38 +3723,63 @@ void tst_QDateTime::timeZones() const #endif } -void tst_QDateTime::systemTimeZoneChange() const +void tst_QDateTime::systemTimeZoneChange_data() const { #ifdef Q_OS_WINRT QSKIP("UWP applications cannot change the system`s time zone (sandboxing)"); #endif - // Set the timezone to Brisbane time - TimeZoneRollback useZone(QByteArray("AEST-10:00")); + QTest::addColumn<QDate>("date"); + QTest::newRow("short") << QDate(1970, 1, 1); + QTest::newRow("2012") << QDate(2012, 6, 1); // short on 64-bit, pimpled on 32-bit + QTest::newRow("pimpled") << QDate(1150000, 6, 1); +} + +void tst_QDateTime::systemTimeZoneChange() const +{ + QFETCH(const QDate, date); + const QTime early(2, 15, 30); - QDateTime localDate = QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::LocalTime); - QDateTime utcDate = QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::UTC); + // Start out in Brisbane time: + TimeZoneRollback useZone(QByteArray("AEST-10:00")); + if (QDateTime(date, early, Qt::LocalTime).offsetFromUtc() != 600 * 60) + QSKIP("Test depends on system support for changing zone to AEST-10:00"); #if QT_CONFIG(timezone) - QDateTime tzDate = QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), QTimeZone("Australia/Brisbane")); + QVERIFY(QTimeZone::systemTimeZone().isValid()); #endif - qint64 localMsecs = localDate.toMSecsSinceEpoch(); - qint64 utcMsecs = utcDate.toMSecsSinceEpoch(); + + const QDateTime localDate = QDateTime(date, early, Qt::LocalTime); + const QDateTime utcDate = QDateTime(date, early, Qt::UTC); + const qint64 localMsecs = localDate.toMSecsSinceEpoch(); + const qint64 utcMsecs = utcDate.toMSecsSinceEpoch(); #if QT_CONFIG(timezone) - qint64 tzMsecs = tzDate.toMSecsSinceEpoch(); + const QTimeZone aest("Australia/Brisbane"); // no transitions since 1992 + // Check that Australia/Brisbane is known: + QVERIFY(aest.isValid()); + const QDateTime tzDate = QDateTime(date, early, aest); - // check that Australia/Brisbane is known + // Check we got the right zone ! QVERIFY(tzDate.timeZone().isValid()); + QCOMPARE(tzDate.timeZone(), aest); + const qint64 tzMsecs = tzDate.toMSecsSinceEpoch(); #endif // Change to Indian time useZone.reset(QByteArray("IST-05:30")); + if (QDateTime(date, early, Qt::LocalTime).offsetFromUtc() != 330 * 60) + QSKIP("Test depends on system support for changing zone to IST-05:30"); +#if QT_CONFIG(timezone) + QVERIFY(QTimeZone::systemTimeZone().isValid()); +#endif - QCOMPARE(localDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::LocalTime)); - QVERIFY(localMsecs != localDate.toMSecsSinceEpoch()); - QCOMPARE(utcDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::UTC)); + QCOMPARE(localDate, QDateTime(date, early, Qt::LocalTime)); + // Note: localDate.toMSecsSinceEpoch == localMsecs, unchanged, iff localDate is pimpled. + QVERIFY(localMsecs != QDateTime(date, early, Qt::LocalTime).toMSecsSinceEpoch()); + QCOMPARE(utcDate, QDateTime(date, early, Qt::UTC)); QCOMPARE(utcDate.toMSecsSinceEpoch(), utcMsecs); #if QT_CONFIG(timezone) - QCOMPARE(tzDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), QTimeZone("Australia/Brisbane"))); QCOMPARE(tzDate.toMSecsSinceEpoch(), tzMsecs); + QCOMPARE(tzDate.timeZone(), aest); + QCOMPARE(tzDate, QDateTime(date, early, aest)); #endif } diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp index 66f6b5163c..a59b58d57f 100644 --- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp @@ -62,6 +62,7 @@ private slots: void windowsId(); void isValidId_data(); void isValidId(); + void malformed(); // Backend tests void utcTest(); void icuTest(); @@ -931,6 +932,21 @@ void tst_QTimeZone::isValidId() #endif } +void tst_QTimeZone::malformed() +{ + // Regression test for QTBUG-92808 + // Strings that look enough like a POSIX zone specifier that the constructor + // accepts them, but the specifier is invalid. + // Must not crash or trigger assertions when calling offsetFromUtc() + const QDateTime now = QDateTime::currentDateTime(); + QTimeZone barf("QUT4tCZ0 , /"); + if (barf.isValid()) + barf.offsetFromUtc(now); + barf = QTimeZone("QtC+09,,MA"); + if (barf.isValid()) + barf.offsetFromUtc(now); +} + void tst_QTimeZone::utcTest() { #ifdef QT_BUILD_INTERNAL |