diff options
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestmouse.cpp | 47 | ||||
-rw-r--r-- | src/testlib/qtestmouse.h | 22 | ||||
-rw-r--r-- | src/testlib/testlib.pro | 1 |
3 files changed, 59 insertions, 11 deletions
diff --git a/src/testlib/qtestmouse.cpp b/src/testlib/qtestmouse.cpp new file mode 100644 index 0000000000..99a75744fa --- /dev/null +++ b/src/testlib/qtestmouse.cpp @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the QtTest module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/QtGlobal> +#include <QtCore/qnamespace.h> +#include <QtTest/qtest_global.h> + +QT_BEGIN_NAMESPACE + +namespace QTest { + +Q_TESTLIB_EXPORT Qt::MouseButton lastMouseButton = Qt::NoButton; +Q_TESTLIB_EXPORT int lastMouseTimestamp = 0; + +} // namespace QTest + +QT_END_NAMESPACE diff --git a/src/testlib/qtestmouse.h b/src/testlib/qtestmouse.h index 5f69463867..fa6bb29d3a 100644 --- a/src/testlib/qtestmouse.h +++ b/src/testlib/qtestmouse.h @@ -64,6 +64,9 @@ namespace QTest { enum MouseAction { MousePress, MouseRelease, MouseClick, MouseDClick, MouseMove }; + extern Q_TESTLIB_EXPORT Qt::MouseButton lastMouseButton; + extern Q_TESTLIB_EXPORT int lastMouseTimestamp; + static void waitForEvents() { #ifdef Q_OS_MAC @@ -84,9 +87,6 @@ namespace QTest QTest::qWarn("Mouse event occurs outside of target window."); } - static Qt::MouseButton lastButton = Qt::NoButton; - static int timestamp = 0; - if (delay == -1 || delay < defaultMouseDelay()) delay = defaultMouseDelay(); if (delay > 0) @@ -105,23 +105,23 @@ namespace QTest switch (action) { case MouseDClick: - qt_handleMouseEvent(w, pos, global, button, stateKey, timestamp); - qt_handleMouseEvent(w, pos, global, Qt::NoButton, stateKey, ++timestamp); + qt_handleMouseEvent(w, pos, global, button, stateKey, lastMouseTimestamp); + qt_handleMouseEvent(w, pos, global, Qt::NoButton, stateKey, ++lastMouseTimestamp); // fall through case MousePress: case MouseClick: - qt_handleMouseEvent(w, pos, global, button, stateKey, ++timestamp); - lastButton = button; + qt_handleMouseEvent(w, pos, global, button, stateKey, ++lastMouseTimestamp); + lastMouseButton = button; if (action == MousePress) break; // fall through case MouseRelease: - qt_handleMouseEvent(w, pos, global, Qt::NoButton, stateKey, ++timestamp); - timestamp += 500; // avoid double clicks being generated - lastButton = Qt::NoButton; + qt_handleMouseEvent(w, pos, global, Qt::NoButton, stateKey, ++lastMouseTimestamp); + lastMouseTimestamp += 500; // avoid double clicks being generated + lastMouseButton = Qt::NoButton; break; case MouseMove: - qt_handleMouseEvent(w, pos, global, lastButton, stateKey, ++timestamp); + qt_handleMouseEvent(w, pos, global, lastMouseButton, stateKey, ++lastMouseTimestamp); // No QCursor::setPos() call here. That could potentially result in mouse events sent by the windowing system // which is highly undesired here. Tests must avoid relying on QCursor. break; diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro index 52bcdd097b..2d9bae5f31 100644 --- a/src/testlib/testlib.pro +++ b/src/testlib/testlib.pro @@ -56,6 +56,7 @@ SOURCES = qtestcase.cpp \ qcsvbenchmarklogger.cpp \ qtestelement.cpp \ qtestelementattribute.cpp \ + qtestmouse.cpp \ qtestxunitstreamer.cpp \ qxunittestlogger.cpp \ qtestblacklist.cpp |