https://bugreports.qt.io/browse/QTBUG-67702 explains that sending mouse move 
and release events outside of a window causes warnings:

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));
}

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 *********

Mouse move and release events occurring outside of a window is not uncommon, so 
there should be a way to disable these warnings.

Using QTest::ignoreWarning() has no effect here, because the message logger 
system is (probably intentionally) bypassed.

Does anyone know why this is the case?

Also, does anyone have any ideas about how to solve this?

One suggestion was QTest::mouse*OutsideWindow(), which would work, but could be 
a bit cumbersome if you need to switch from mouseMove to mouseMoveOutsideWindow 
halfway through a "drag" loop.

Another idea could be to have a flag or construct that only applies for the 
duration of a test function, and is reset at the end of that function. I think 
something like this could also be useful for the opposite use case: failing a 
test upon any warnings (something that would be useful for QML applications). 
Something like https://codereview.qt-project.org/#/c/89178/ except it's 
automatically reset for you at the end of each test.
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to