diff options
author | Vladimir Belyavsky <belyavskyv@gmail.com> | 2023-11-17 02:16:58 +0300 |
---|---|---|
committer | Vladimir Belyavsky <belyavskyv@gmail.com> | 2023-11-22 20:15:38 +0000 |
commit | 18aa36cf878a52b8fe991392098e9445c3d3bfe3 (patch) | |
tree | fcbf600c10f272bd76be7d7a0f58b3058b734ba4 /tests/auto/testlib/selftests/warnings/tst_warnings.cpp | |
parent | f2f2b6ef18907a76461b54e110618e7840971fa7 (diff) |
QTest: make failOnWarning() functional on temp objects destruction
We need to be able to handle warnings that may occur when temporary
objects, that were created in a test function, are destroyed.
For example, now we miss all warnings that might be triggered from
the object destructor, if the object's deletion was delayed (e.g. via
deleteLater()). Also we miss all the warnings that were triggered on
the test's cleanup() call.
To fix this we need simply move QTestLog::clearFailOnWarnings()
from QTestResult::finishedCurrentTestData() to the later stage,
i.e. into QTestLog::clearCurrentTestState() which is actually called
in appropriate time from QTestResult::finishedCurrentTestDataCleanup().
Same for QTestLog::clearIgnoreMessages(), since they are interrelated,
so we need to clear them at the same time.
We need this change for QML tests in particularly, to be able
fail on warnings that might be triggered from Component.onDestruction()
of some temporary test object.
Pick-to: 6.6 6.5
Change-Id: I58a57691f20761619f56bd1bea3a862f2c26f569
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/testlib/selftests/warnings/tst_warnings.cpp')
-rw-r--r-- | tests/auto/testlib/selftests/warnings/tst_warnings.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/auto/testlib/selftests/warnings/tst_warnings.cpp b/tests/auto/testlib/selftests/warnings/tst_warnings.cpp index c113fdaf25..3dd9a7afe2 100644 --- a/tests/auto/testlib/selftests/warnings/tst_warnings.cpp +++ b/tests/auto/testlib/selftests/warnings/tst_warnings.cpp @@ -27,6 +27,7 @@ private slots: void testFailOnWarningsThenSkip(); #endif void testFailOnWarningsAndIgnoreWarnings(); + void testFailOnTemporaryObjectDestruction(); }; void tst_Warnings::testWarnings() @@ -208,6 +209,27 @@ void tst_Warnings::testFailOnWarningsAndIgnoreWarnings() qWarning(warningStr); } +void tst_Warnings::testFailOnTemporaryObjectDestruction() +{ + QTest::failOnWarning("Running low on toothpaste!"); + QTest::ignoreMessage(QtWarningMsg, "Ran out of cabbage!"); + + class TestObject : public QObject + { + public: + ~TestObject() + { + // Shouldn't fail - ignored + qWarning("Ran out of cabbage!"); + // Should fail + qWarning("Running low on toothpaste!"); + } + }; + + QScopedPointer<TestObject, QScopedPointerDeleteLater> testObject(new TestObject); + QVERIFY(testObject); +} + QTEST_MAIN(tst_Warnings) #include "tst_warnings.moc" |