diff options
Diffstat (limited to 'tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp')
-rw-r--r-- | tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp | 89 |
1 files changed, 39 insertions, 50 deletions
diff --git a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp index 42a5f4d593..f703111384 100644 --- a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp +++ b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp @@ -1,37 +1,14 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> #include <qevent.h> #include <qwindow.h> #include <QtGui/private/qpointingdevice_p.h> +#include <QtCore/qpointer.h> + Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests") class MouseEventWidget : public QWindow @@ -122,6 +99,7 @@ private slots: void grabbers_data(); void grabbers(); void velocity(); + void clone(); private: MouseEventWidget* testMouseWidget; @@ -159,6 +137,7 @@ void tst_QMouseEvent::mouseEventBasic() QMouseEvent me(QEvent::MouseButtonPress, local, scene, screen, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QVERIFY(me.isInputEvent()); QVERIFY(me.isPointerEvent()); + QVERIFY(me.isSinglePointEvent()); QCOMPARE(me.isAccepted(), true); QCOMPARE(me.button(), Qt::LeftButton); QCOMPARE(me.buttons(), Qt::LeftButton); @@ -168,26 +147,17 @@ void tst_QMouseEvent::mouseEventBasic() QCOMPARE(me.scenePosition(), scene); QCOMPARE(me.globalPosition(), screen); // Press right button while left is already pressed - me = QMouseEvent(QEvent::MouseButtonPress, local, scene, screen, Qt::RightButton, Qt::LeftButton | Qt::RightButton, Qt::NoModifier); - QVERIFY(me.isBeginEvent()); - QVERIFY(!me.isEndEvent()); + QMouseEvent me2(QEvent::MouseButtonPress, local, scene, screen, Qt::RightButton, Qt::LeftButton | Qt::RightButton, Qt::NoModifier); + QVERIFY(me2.isBeginEvent()); + QVERIFY(!me2.isEndEvent()); // Release right button while left is still pressed - me = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::RightButton, Qt::LeftButton, Qt::NoModifier); - QVERIFY(!me.isBeginEvent()); - QVERIFY(me.isEndEvent()); + QMouseEvent me3 = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::RightButton, Qt::LeftButton, Qt::NoModifier); + QVERIFY(!me3.isBeginEvent()); + QVERIFY(me3.isEndEvent()); // Release left button in the usual way - me = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); - QVERIFY(!me.isBeginEvent()); - QVERIFY(me.isEndEvent()); - // Try out the copy constructor - QMouseEvent copy(me); - QVERIFY(copy.isInputEvent()); - QVERIFY(copy.isPointerEvent()); - QVERIFY(!copy.isBeginEvent()); - QVERIFY(copy.isEndEvent()); - QCOMPARE(copy.position(), local); - QCOMPARE(copy.scenePosition(), scene); - QCOMPARE(copy.globalPosition(), screen); + QMouseEvent me4 = QMouseEvent(QEvent::MouseButtonRelease, local, scene, screen, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); + QVERIFY(!me4.isBeginEvent()); + QVERIFY(me4.isEndEvent()); } void tst_QMouseEvent::checkMousePressEvent_data() @@ -296,14 +266,14 @@ void tst_QMouseEvent::grabbers() auto firstEPD = devPriv->pointById(0); QCOMPARE(firstEPD->eventPoint.pressTimestamp(), testMouseWidget->pressTimestamp); QCOMPARE(firstEPD->exclusiveGrabber, grabExclusive ? testMouseWidget : nullptr); - QCOMPARE(firstEPD->passiveGrabbers.count(), grabPassive ? 1 : 0); + QCOMPARE(firstEPD->passiveGrabbers.size(), grabPassive ? 1 : 0); if (grabPassive) QCOMPARE(firstEPD->passiveGrabbers.first(), testMouseWidget); // Ensure that grabbers are forgotten after release delivery QTest::mouseRelease(testMouseWidget, Qt::LeftButton, Qt::KeyboardModifiers(), {10, 10}); QTRY_COMPARE(firstEPD->exclusiveGrabber, nullptr); - QCOMPARE(firstEPD->passiveGrabbers.count(), 0); + QCOMPARE(firstEPD->passiveGrabbers.size(), 0); } void tst_QMouseEvent::velocity() @@ -342,5 +312,24 @@ void tst_QMouseEvent::velocity() QVERIFY(testMouseWidget->velocity.y() > 0); } +void tst_QMouseEvent::clone() +{ + const QPointF pos(10.0f, 10.0f); + + QMouseEvent originalMe(QEvent::MouseButtonPress, pos, pos, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); + QVERIFY(!originalMe.allPointsAccepted()); + QVERIFY(!originalMe.points().first().isAccepted()); + + // create a clone of the original + std::unique_ptr<QMouseEvent> clonedMe(originalMe.clone()); + QVERIFY(!clonedMe->allPointsAccepted()); + QVERIFY(!clonedMe->points().first().isAccepted()); + + // now we alter originalMe, which should *not* change clonedMe + originalMe.setAccepted(true); + QVERIFY(!clonedMe->allPointsAccepted()); + QVERIFY(!clonedMe->points().first().isAccepted()); +} + QTEST_MAIN(tst_QMouseEvent) #include "tst_qmouseevent.moc" |