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

QTest::ignoreMessage() fails to match regex against warning string

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • None
    • 5.6.3, 5.11
    • Testing: qtestlib
    • None

    Description

      Sending mouse events outside of a window is something that happens in real world scenarios: dragging a selection past the edge of the window to scroll a canvas, for example. As sending these events does actually work, there should be a way to ignore the unwanted warnings that testlib produces.

      hasMatch() returns true, but the test still fails:

      #include <QtTest>
      
      // add necessary includes here
      
      class Test : public QObject
      {
          Q_OBJECT
      
      public:
          Test();
          ~Test();
      
      private slots:
          void test_case1();
      
      };
      
      Test::Test()
      {
      
      }
      
      Test::~Test()
      {
      
      }
      
      void Test::test_case1()
      {
          QWindow window;
          window.resize(400, 400);
      
          // Start inside and drag outside (e.g. moving a selection to the edge of a
          // canvas should scroll the canvas).
          QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 200));
      
          const QRegularExpression regex(".*Mouse event at .* occurs outside of target window.*");
          QVERIFY(regex.isValid());
      
          const QRegularExpressionMatch match(regex.match("Mouse event at 600, 600 occurs outside of target window (400x400)."));
          QVERIFY(match.hasMatch());
      
          QTest::ignoreMessage(QtWarningMsg, regex);
          QTest::mouseMove(&window, QPoint(600, 600));
      
          QTest::ignoreMessage(QtWarningMsg, regex);
          QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(600, 600));
      }
      
      QTEST_MAIN(Test)
      
      #include "tst_test.moc"
      
      output
      ********* Start testing of Test *********
      Config: Using QtTest library 5.11.0, Qt 5.11.0 (x86_64-little_endian-llp64 shared (dynamic) debug build; by MSVC 2017)
      PASS   : Test::initTestCase()
      WARNING: Test::test_case1() Mouse event at 600, 600 occurs outside of target window (400x400).
      WARNING: Test::test_case1() Mouse event at 600, 600 occurs outside of target window (400x400).
      INFO   : Test::test_case1() Did not receive any message matching: ".*Mouse event at .* occurs outside of target window.*"
      INFO   : Test::test_case1() Did not receive any message matching: ".*Mouse event at .* occurs outside of target window.*"
      FAIL!  : Test::test_case1() Not all expected messages were received
      PASS   : Test::cleanupTestCase()
      Totals: 2 passed, 1 failed, 0 skipped, 0 blacklisted, 1ms
      ********* Finished testing of Test *********
      

      Attachments

        Issue Links

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

          Activity

            People

              macadder Jason McDonald
              mitch_curtis Mitch Curtis
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes