Maintain at least 500ms timestamp distance between each test function
If we had one test function that just did tst_Mouse::f1() { QTest::mouseMove(w, QPoint(0,0)); } and another test function that did tst_Mouse::f2() { QTest::mouseMove(w, QPoint(500,500)); } their corresponding event timestamps were only 1 apart from each other. This meant that any code that tried to estimate the velocity of a mouse cursor would get a really high velocity estimate inside f2(). This would come as a surprise to most people. So to avoid this, we add a 500 ms timestamp delay between each test function call. In theory this could also prevent generating a mouseDoubleClickEvent when a pair of test functions containing a press-release sequence was run, but there is a separate pre-existing mechanism to handle that case. Change-Id: Icd4fc35853c09f080466d22411208c7b5c4174b5 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
6d6ca70538
commit
8c6c4df3e8
@ -296,6 +296,8 @@ namespace QTestPrivate
|
||||
|
||||
namespace QTest
|
||||
{
|
||||
extern Q_TESTLIB_EXPORT int lastMouseTimestamp;
|
||||
|
||||
class WatchDog;
|
||||
|
||||
static QObject *currentTestObject = nullptr;
|
||||
@ -1173,6 +1175,7 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
|
||||
QTestPrivate::qtestMouseButtons = Qt::NoButton;
|
||||
if (watchDog)
|
||||
watchDog->beginTest();
|
||||
QTest::lastMouseTimestamp += 500; // Maintain at least 500ms mouse event timestamps between each test function call
|
||||
invokeTestOnData(index);
|
||||
if (watchDog)
|
||||
watchDog->testFinished();
|
||||
|
@ -42,6 +42,8 @@ class tst_Mouse : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void timestampBetweenTestFunction_data();
|
||||
void timestampBetweenTestFunction();
|
||||
void stateHandlingPart1_data();
|
||||
void stateHandlingPart1();
|
||||
void stateHandlingPart2();
|
||||
@ -55,20 +57,83 @@ public:
|
||||
Qt::MouseButtons stateInMouseMove = Qt::NoButton;
|
||||
int moveCount = 0;
|
||||
int pressCount = 0;
|
||||
int doubleClickCount = 0;
|
||||
ulong lastTimeStamp = 0;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *)
|
||||
void mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
pressCount++;
|
||||
processEvent(e);
|
||||
}
|
||||
|
||||
void mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
moveCount++;
|
||||
stateInMouseMove = e->buttons();
|
||||
processEvent(e);
|
||||
}
|
||||
|
||||
void mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
processEvent(e);
|
||||
}
|
||||
|
||||
void mouseDoubleClickEvent(QMouseEvent *e)
|
||||
{
|
||||
doubleClickCount++;
|
||||
processEvent(e);
|
||||
}
|
||||
|
||||
void processEvent(QMouseEvent *e)
|
||||
{
|
||||
lastTimeStamp = e->timestamp();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
static ulong lastTimeStampInPreviousTestFunction = 0;
|
||||
|
||||
void tst_Mouse::timestampBetweenTestFunction_data()
|
||||
{
|
||||
QTest::addColumn<bool>("hoverLast");
|
||||
QTest::addColumn<bool>("pressAndRelease");
|
||||
QTest::newRow("press, release") << true << false;
|
||||
QTest::newRow("press, release, hover") << true << true;
|
||||
QTest::newRow("hover") << false << true;
|
||||
QTest::newRow("hover #2") << false << true;
|
||||
QTest::newRow("press, release #2") << true << false;
|
||||
QTest::newRow("press, release, hover #2") << true << true;
|
||||
}
|
||||
|
||||
void tst_Mouse::timestampBetweenTestFunction()
|
||||
{
|
||||
QFETCH(bool, hoverLast);
|
||||
QFETCH(bool, pressAndRelease);
|
||||
|
||||
MouseWindow w;
|
||||
w.show();
|
||||
w.setGeometry(100, 100, 200, 200);
|
||||
QVERIFY(QTest::qWaitForWindowActive(&w));
|
||||
|
||||
QPoint point(10, 10);
|
||||
QCOMPARE(w.pressCount, 0);
|
||||
if (pressAndRelease) {
|
||||
QTest::mousePress(&w, Qt::LeftButton, { }, point);
|
||||
QVERIFY(w.lastTimeStamp - lastTimeStampInPreviousTestFunction > 500); // Should be at least 500 ms timestamp between each test case
|
||||
QCOMPARE(w.pressCount, 1);
|
||||
QTest::mouseRelease(&w, Qt::LeftButton, { }, point);
|
||||
}
|
||||
QCOMPARE(w.doubleClickCount, 0);
|
||||
if (hoverLast) {
|
||||
static int xMove = 0;
|
||||
xMove += 5; // Just make sure we generate different hover coordinates
|
||||
point.rx() += xMove;
|
||||
QTest::mouseMove(&w, point); // a hover move. This doesn't generate a timestamp delay of 500 ms
|
||||
}
|
||||
lastTimeStampInPreviousTestFunction = w.lastTimeStamp;
|
||||
}
|
||||
|
||||
void tst_Mouse::stateHandlingPart1_data()
|
||||
{
|
||||
QTest::addColumn<bool>("dummy");
|
||||
|
Loading…
Reference in New Issue
Block a user