Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-104441

REG: No longer possible to use macros or functions that rely on an event loop in cleanup() after failed test function

    XMLWordPrintable

Details

    • 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"
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Eddy Edward Welbourne
            mitch_curtis Mitch Curtis
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: