Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
6.3.0
-
None
-
0462dba766 (qt/qtbase/dev) 0462dba766 (qt/tqtc-qtbase/dev) a111c15c0a (qt/qtbase/6.4) a111c15c0a (qt/tqtc-qtbase/6.4)
Description
Prior to Qt 6.3 I was using cleanup() to clean up my application's state for the next test function. This required the use of QTRY_COMPARE because the application has a dirtying mechanism to batch changes for the next frame. After https://codereview.qt-project.org/c/qt/qtbase/+/359564, this no longer works.
Simplified test case:
#include <QtTest> // add necessary includes here class Blah : public QObject { Q_OBJECT public: Blah() = default; void dirtyGraph() { Q_ASSERT(QMetaObject::invokeMethod(this, &Blah::rebuildGraph, Qt::QueuedConnection)); } signals: void graphRebuilt(); private: void rebuildGraph() { emit graphRebuilt(); } }; class SignalSpy : public QObject { Q_OBJECT public: SignalSpy(); ~SignalSpy(); private slots: void initTestCase(); void cleanup(); void cleanupTestCase(); void doomedToFail(); }; SignalSpy::SignalSpy() { } SignalSpy::~SignalSpy() { } void SignalSpy::doomedToFail() { QFAIL("oops"); } void SignalSpy::initTestCase() { } void SignalSpy::cleanup() { Blah b; QSignalSpy graphRebuiltSpy(&b, SIGNAL(graphRebuilt())); QVERIFY(graphRebuiltSpy.isValid()); // The graph would be cleared here to make way for the next test. b.dirtyGraph(); QVERIFY(graphRebuiltSpy.wait()); // QTRY_COMPARE(graphRebuiltSpy.count(), 1); } void SignalSpy::cleanupTestCase() { } QTEST_MAIN(SignalSpy) #include "tst_signalspy.moc"