That warning message was added by [1]. I have never fully understood the 
motivation for that warning. The documentation from [2] does not say if global 
coordinates are allowed. QTest sends all mouse events down to 
QWindowSystemInterface, which does expect a window as an argument, or nullptr 
on window-less systems (eglfs). So if you want to simulate a mouse 
move/press/release outside a window you could try to use that code path... but 
it won't work AFAICT 😊 see [3], if we don't find a window under mouse, then 
QGuiApplicationPrivate::processMouseEvent() returns. Otherwise, where should we 
send the event?


[1] https://codereview.qt-project.org/#/c/53474/

[2] http://doc.qt.io/qt-5/qtest.html#mouseMove

[3] 
http://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/kernel/qguiapplication.cpp#n2021

________________________________
From: Development <development-bounces+gatis.paeglis=qt...@qt-project.org> on 
behalf of Mitch Curtis <mitch.cur...@qt.io>
Sent: Monday, April 16, 2018 11:56:56 AM
To: development@qt-project.org
Subject: [Development] QTestLib: sending mouse move and release events outside 
windows

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
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to