summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/kernel')
-rw-r--r--tests/auto/widgets/kernel/kernel.pro4
-rw-r--r--tests/auto/widgets/kernel/qaction/tst_qaction.cpp35
-rw-r--r--tests/auto/widgets/kernel/qgesturerecognizer/BLACKLIST2
-rw-r--r--tests/auto/widgets/kernel/qgesturerecognizer/qgesturerecognizer.pro4
-rw-r--r--tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp337
-rw-r--r--tests/auto/widgets/kernel/qwidget/BLACKLIST2
-rw-r--r--tests/auto/widgets/kernel/qwidget/qwidget.pro2
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp12
-rw-r--r--tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp70
9 files changed, 462 insertions, 6 deletions
diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro
index 20720dc928..73fd934502 100644
--- a/tests/auto/widgets/kernel/kernel.pro
+++ b/tests/auto/widgets/kernel/kernel.pro
@@ -6,6 +6,7 @@ SUBDIRS=\
qboxlayout \
qdesktopwidget \
qformlayout \
+ qgesturerecognizer \
qgridlayout \
qlayout \
qstackedlayout \
@@ -19,4 +20,7 @@ SUBDIRS=\
qshortcut \
qsizepolicy
+darwin:SUBDIRS -= \ # Uses native recognizers
+ qgesturerecognizer \
+
SUBDIRS -= qsound
diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
index 83e1850524..ac6362168e 100644
--- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
+++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp
@@ -62,6 +62,7 @@ private slots:
void task229128TriggeredSignalWithoutActiongroup();
void task229128TriggeredSignalWhenInActiongroup();
void repeat();
+ void keysequence(); // QTBUG-53381
private:
int m_lastEventType;
@@ -276,6 +277,40 @@ void tst_QAction::alternateShortcuts()
QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
}
+void tst_QAction::keysequence()
+{
+ MyWidget testWidget(this);
+ testWidget.show();
+ QApplication::setActiveWindow(&testWidget);
+
+ {
+ QAction act(&testWidget);
+ testWidget.addAction(&act);
+
+ QKeySequence ks(QKeySequence::SelectAll);
+
+ act.setShortcut(ks);
+
+ QSignalSpy spy(&act, &QAction::triggered);
+
+ act.setAutoRepeat(true);
+ QTest::keySequence(&testWidget, ks);
+ QCoreApplication::processEvents();
+ QCOMPARE(spy.count(), 1); // act should have been triggered
+
+ act.setAutoRepeat(false);
+ QTest::keySequence(&testWidget, ks);
+ QCoreApplication::processEvents();
+ QCOMPARE(spy.count(), 2); //act should have been triggered a 2nd time
+
+ // end of the scope of the action, it will be destroyed and removed from widget
+ // This action should also unregister its shortcuts
+ }
+
+ // this tests a crash (if the action did not unregister its alternate shortcuts)
+ QTest::keyClick(&testWidget, Qt::Key_A, Qt::ControlModifier);
+}
+
void tst_QAction::enabledVisibleInteraction()
{
MyWidget testWidget(this);
diff --git a/tests/auto/widgets/kernel/qgesturerecognizer/BLACKLIST b/tests/auto/widgets/kernel/qgesturerecognizer/BLACKLIST
new file mode 100644
index 0000000000..7f55c2dae0
--- /dev/null
+++ b/tests/auto/widgets/kernel/qgesturerecognizer/BLACKLIST
@@ -0,0 +1,2 @@
+[panGesture:Two finger]
+xcb
diff --git a/tests/auto/widgets/kernel/qgesturerecognizer/qgesturerecognizer.pro b/tests/auto/widgets/kernel/qgesturerecognizer/qgesturerecognizer.pro
new file mode 100644
index 0000000000..7c9ddcfb03
--- /dev/null
+++ b/tests/auto/widgets/kernel/qgesturerecognizer/qgesturerecognizer.pro
@@ -0,0 +1,4 @@
+CONFIG += testcase
+TARGET = tst_qgesturerecognizer
+QT += widgets testlib gui-private core-private
+SOURCES += tst_qgesturerecognizer.cpp
diff --git a/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp b/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp
new file mode 100644
index 0000000000..c3ebb838bb
--- /dev/null
+++ b/tests/auto/widgets/kernel/qgesturerecognizer/tst_qgesturerecognizer.cpp
@@ -0,0 +1,337 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 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/QTest>
+#include <QtWidgets/QApplication>
+#include <QtWidgets/QWidget>
+#include <QtWidgets/QGestureEvent>
+#include <QtGui/QScreen>
+#include <QtGui/QTouchDevice>
+#include <QtCore/QVector>
+#include <QtCore/QString>
+#include <QtCore/QHash>
+#include <QtCore/QDebug>
+
+class tst_QGestureRecognizer : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QGestureRecognizer();
+
+private Q_SLOTS:
+ void initTestCase();
+#ifndef QT_NO_GESTURES
+ void panGesture_data();
+ void panGesture();
+ void pinchGesture_data();
+ void pinchGesture();
+ void swipeGesture_data();
+ void swipeGesture();
+#endif // !QT_NO_GESTURES
+
+private:
+ const int m_fingerDistance;
+ QTouchDevice *m_touchDevice;
+};
+
+tst_QGestureRecognizer::tst_QGestureRecognizer()
+ : m_fingerDistance(qRound(QGuiApplication::primaryScreen()->physicalDotsPerInch() / 2.0))
+ , m_touchDevice(QTest::createTouchDevice())
+{
+ qputenv("QT_PAN_TOUCHPOINTS", "2"); // Prevent device detection of pan touch point count.
+}
+
+void tst_QGestureRecognizer::initTestCase()
+{
+}
+
+#ifndef QT_NO_GESTURES
+
+typedef QVector<Qt::GestureType> GestureTypeVector;
+
+class TestWidget : public QWidget
+{
+public:
+ explicit TestWidget(const GestureTypeVector &gestureTypes);
+
+ bool gestureReceived(Qt::GestureType gestureType) const
+ { return m_receivedGestures.value(gestureType); }
+
+protected:
+ bool event(QEvent * event) Q_DECL_OVERRIDE;
+
+private:
+ typedef QHash<Qt::GestureType, bool> GestureTypeHash;
+ GestureTypeHash m_receivedGestures;
+};
+
+TestWidget::TestWidget(const GestureTypeVector &gestureTypes)
+{
+ setAttribute(Qt::WA_AcceptTouchEvents);
+
+ foreach (Qt::GestureType gestureType, gestureTypes) {
+ grabGesture(gestureType);
+ m_receivedGestures.insert(gestureType, false);
+ }
+
+ const QRect geometry = QGuiApplication::primaryScreen()->availableGeometry();
+ const QSize size = geometry.size() / 2;
+ resize(size);
+ move(geometry.center() - QPoint(size.width() / 2, size.height() / 2));
+}
+
+bool TestWidget::event(QEvent * event)
+{
+ switch (event->type()) {
+ case QEvent::Gesture: {
+ const QGestureEvent *gestureEvent = static_cast<QGestureEvent *>(event);
+ const GestureTypeHash::iterator hend = m_receivedGestures.end();
+ for (GestureTypeHash::iterator it = m_receivedGestures.begin(); it != hend; ++it) {
+ if (const QGesture *gesture = gestureEvent->gesture(it.key())) {
+ if (gesture->state() == Qt::GestureFinished)
+ it.value() = true;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return QWidget::event(event);
+}
+
+static void pressSequence(QTest::QTouchEventSequence &sequence,
+ QVector<QPoint> &points,
+ QWidget *widget)
+{
+ const int pointCount = points.size();
+ for (int p = 0; p < pointCount; ++p)
+ sequence.press(p, points.at(p), widget);
+ sequence.commit();
+}
+
+static void linearSequence(int n, const QPoint &delta,
+ QTest::QTouchEventSequence &sequence,
+ QVector<QPoint> &points,
+ QWidget *widget)
+{
+ const int pointCount = points.size();
+ for (int s = 0; s < n; ++s) {
+ for (int p = 0; p < pointCount; ++p) {
+ points[p] += delta;
+ sequence.move(p, points[p], widget);
+ }
+ sequence.commit();
+ }
+}
+
+static void releaseSequence(QTest::QTouchEventSequence &sequence,
+ QVector<QPoint> &points,
+ QWidget *widget)
+{
+ const int pointCount = points.size();
+ for (int p = 0; p < pointCount; ++p)
+ sequence.release(p, points[p], widget);
+ sequence.commit();
+}
+
+// --- Pan
+
+enum PanSubTest {
+ TwoFingerPanSubTest
+};
+
+void tst_QGestureRecognizer::panGesture_data()
+{
+ QTest::addColumn<int>("panSubTest");
+ QTest::addColumn<bool>("gestureExpected");
+ QTest::newRow("Two finger") << int(TwoFingerPanSubTest) << true;
+}
+
+void tst_QGestureRecognizer::panGesture()
+{
+ QFETCH(int, panSubTest);
+ QFETCH(bool, gestureExpected);
+
+ Q_UNUSED(panSubTest) // Single finger pan will be added later.
+
+ const int panPoints = 2;
+ const Qt::GestureType gestureType = Qt::PanGesture;
+ TestWidget widget(GestureTypeVector(1, gestureType));
+ widget.setWindowTitle(QTest::currentTestFunction());
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
+
+ QVector<QPoint> points;
+ for (int i = 0; i < panPoints; ++i)
+ points.append(QPoint(10 + i *20, 10 + i *20));
+
+ QTest::QTouchEventSequence panSequence = QTest::touchEvent(&widget, m_touchDevice);
+ pressSequence(panSequence, points, &widget);
+ linearSequence(5, QPoint(20, 20), panSequence, points, &widget);
+ releaseSequence(panSequence, points, &widget);
+
+ if (gestureExpected) {
+ QTRY_VERIFY(widget.gestureReceived(gestureType));
+ } else {
+ QCoreApplication::processEvents();
+ QVERIFY(!widget.gestureReceived(gestureType));
+ }
+}
+
+// --- Pinch
+
+enum PinchSubTest {
+ StandardPinchSubTest
+};
+
+void tst_QGestureRecognizer::pinchGesture_data()
+{
+ QTest::addColumn<int>("pinchSubTest");
+ QTest::addColumn<bool>("gestureExpected");
+ QTest::newRow("Standard") << int(StandardPinchSubTest) << true;
+}
+
+void tst_QGestureRecognizer::pinchGesture()
+{
+ QFETCH(int, pinchSubTest);
+ QFETCH(bool, gestureExpected);
+
+ Q_UNUSED(pinchSubTest)
+
+ const Qt::GestureType gestureType = Qt::PinchGesture;
+ TestWidget widget(GestureTypeVector(1, gestureType));
+ widget.setWindowTitle(QTest::currentTestFunction());
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
+
+ QVector<QPoint> points;
+ points.append(widget.rect().center());
+ points.append(points.front() + QPoint(0, 20));
+
+ QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(&widget, m_touchDevice);
+ pressSequence(pinchSequence, points, &widget);
+
+ for (int s = 0; s < 5; ++s) {
+ points[0] += QPoint(5, 30);
+ pinchSequence.move(0, points[0], &widget);
+ points[1] += QPoint(5, -30);
+ pinchSequence.move(1, points[1], &widget);
+ pinchSequence.commit();
+ }
+
+ releaseSequence(pinchSequence, points, &widget);
+
+ if (gestureExpected) {
+ QTRY_VERIFY(widget.gestureReceived(gestureType));
+ } else {
+ QCoreApplication::processEvents();
+ QVERIFY(!widget.gestureReceived(gestureType));
+ }
+}
+
+// --- Swipe
+
+enum SwipeSubTest {
+ SwipeLineSubTest,
+ SwipeDirectionChangeSubTest,
+ SwipeSmallDirectionChangeSubTest
+};
+
+void tst_QGestureRecognizer::swipeGesture_data()
+{
+ QTest::addColumn<int>("swipeSubTest");
+ QTest::addColumn<bool>("gestureExpected");
+ QTest::newRow("Line") << int(SwipeLineSubTest) << true;
+ QTest::newRow("DirectionChange") << int(SwipeDirectionChangeSubTest) << false;
+ QTest::newRow("SmallDirectionChange") << int(SwipeSmallDirectionChangeSubTest) << true;
+}
+
+void tst_QGestureRecognizer::swipeGesture()
+{
+ enum { swipePoints = 3 };
+
+ QFETCH(int, swipeSubTest);
+ QFETCH(bool, gestureExpected);
+
+ const Qt::GestureType gestureType = Qt::SwipeGesture;
+ TestWidget widget(GestureTypeVector(1, gestureType));
+ widget.setWindowTitle(QTest::currentTestFunction());
+ widget.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&widget));
+
+ // Start a swipe sequence with 2 points (QTBUG-15768)
+ const QPoint fingerDistance(m_fingerDistance, m_fingerDistance);
+ QVector<QPoint> points;
+ for (int i = 0; i < swipePoints - 1; ++i)
+ points.append(fingerDistance + i * fingerDistance);
+
+ QTest::QTouchEventSequence swipeSequence = QTest::touchEvent(&widget, m_touchDevice);
+ pressSequence(swipeSequence, points, &widget);
+
+ // Press point #3
+ points.append(points.last() + fingerDistance);
+ swipeSequence.press(points.size() - 1, points.last(), &widget);
+ swipeSequence.commit();
+ Q_ASSERT(points.size() == swipePoints);
+
+ // Move.
+ const QPoint moveDelta(60, 20);
+ switch (swipeSubTest) {
+ case SwipeLineSubTest:
+ linearSequence(5, moveDelta, swipeSequence, points, &widget);
+ break;
+ case SwipeDirectionChangeSubTest:
+ linearSequence(5, moveDelta, swipeSequence, points, &widget);
+ linearSequence(3, QPoint(-moveDelta.x(), moveDelta.y()), swipeSequence, points, &widget);
+ break;
+ case SwipeSmallDirectionChangeSubTest: { // QTBUG-46195, small changes in direction should not cause the gesture to be canceled.
+ const QPoint smallChangeMoveDelta(50, 1);
+ linearSequence(5, smallChangeMoveDelta, swipeSequence, points, &widget);
+ linearSequence(1, QPoint(smallChangeMoveDelta.x(), -3), swipeSequence, points, &widget);
+ linearSequence(5, smallChangeMoveDelta, swipeSequence, points, &widget);
+ }
+ break;
+ }
+
+ releaseSequence(swipeSequence, points, &widget);
+
+ if (gestureExpected) {
+ QTRY_VERIFY(widget.gestureReceived(gestureType));
+ } else {
+ QCoreApplication::processEvents();
+ QVERIFY(!widget.gestureReceived(gestureType));
+ }
+}
+
+#endif // !QT_NO_GESTURES
+
+QTEST_MAIN(tst_QGestureRecognizer)
+
+#include "tst_qgesturerecognizer.moc"
diff --git a/tests/auto/widgets/kernel/qwidget/BLACKLIST b/tests/auto/widgets/kernel/qwidget/BLACKLIST
index 010e96467c..8e8602840e 100644
--- a/tests/auto/widgets/kernel/qwidget/BLACKLIST
+++ b/tests/auto/widgets/kernel/qwidget/BLACKLIST
@@ -72,7 +72,7 @@ osx
[setClearAndResizeMask]
osx
[setToolTip]
-osx-10.9
+osx
[moveInResizeEvent]
ubuntu-14.04
[moveChild:right]
diff --git a/tests/auto/widgets/kernel/qwidget/qwidget.pro b/tests/auto/widgets/kernel/qwidget/qwidget.pro
index 499ca65516..0e95d454cf 100644
--- a/tests/auto/widgets/kernel/qwidget/qwidget.pro
+++ b/tests/auto/widgets/kernel/qwidget/qwidget.pro
@@ -12,7 +12,7 @@ aix-g++*:QMAKE_CXXFLAGS+=-fpermissive
CONFIG += x11inc
mac {
- LIBS += -framework Security -framework AppKit -framework Carbon
+ LIBS += -framework Security -framework AppKit
OBJECTIVE_SOURCES += tst_qwidget_mac_helpers.mm
}
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index baecc43f2c..e284d92f72 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -1800,9 +1800,11 @@ void tst_QWidget::windowState()
QCOMPARE(widget1.pos(), pos);
QCOMPARE(widget1.size(), size);
-#define VERIFY_STATE(s) QCOMPARE(int(widget1.windowState() & stateMask), int(s))
+#define VERIFY_STATE(s) \
+ QCOMPARE(int(widget1.windowState() & stateMask), int(s)); \
+ QCOMPARE(int(widget1.windowHandle()->windowStates() & stateMask), int(s))
- const int stateMask = Qt::WindowMaximized|Qt::WindowMinimized|Qt::WindowFullScreen;
+ const auto stateMask = Qt::WindowMaximized | Qt::WindowMinimized | Qt::WindowFullScreen;
widget1.setWindowState(Qt::WindowMaximized);
QTest::qWait(100);
@@ -8070,8 +8072,8 @@ void tst_QWidget::setMaskInResizeEvent()
QRegion expectedParentUpdate(0, 0, 100, 10); // Old testWidget area.
expectedParentUpdate += testWidget.geometry(); // New testWidget area.
- QCOMPARE(w.paintedRegion, expectedParentUpdate);
- QCOMPARE(testWidget.paintedRegion, testWidget.mask());
+ QTRY_COMPARE(w.paintedRegion, expectedParentUpdate);
+ QTRY_COMPARE(testWidget.paintedRegion, testWidget.mask());
testWidget.paintedRegion = QRegion();
// Now resize the widget again, but in the oposite direction
@@ -10499,6 +10501,8 @@ void tst_QWidget::qmlSetParentHelper()
void tst_QWidget::testForOutsideWSRangeFlag()
{
+ QSKIP("Test assumes QWindows can have 0x0 size, see QTBUG-61953");
+
// QTBUG-49445
{
QWidget widget;
diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
index f20978c295..9dc513c115 100644
--- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
+++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp
@@ -100,6 +100,11 @@ private slots:
void QTBUG_50561_QCocoaBackingStore_paintDevice_crash();
+ void setWindowState_data();
+ void setWindowState();
+
+ void nativeShow();
+
void QTBUG_56277_resize_on_showEvent();
};
@@ -863,6 +868,71 @@ void tst_QWidget_window::QTBUG_50561_QCocoaBackingStore_paintDevice_crash()
w.close();
}
+void tst_QWidget_window::setWindowState_data()
+{
+ QString platformName = QGuiApplication::platformName().toLower();
+
+ QTest::addColumn<Qt::WindowStates>("state");
+ QTest::newRow("0") << Qt::WindowStates();
+ QTest::newRow("Qt::WindowMaximized") << Qt::WindowStates(Qt::WindowMaximized);
+ QTest::newRow("Qt::WindowMinimized") << Qt::WindowStates(Qt::WindowMinimized);
+ QTest::newRow("Qt::WindowFullScreen") << Qt::WindowStates(Qt::WindowFullScreen);
+
+ if (platformName != "xcb" && platformName != "windows" && !platformName.startsWith("wayland")
+ && platformName != "offscreen")
+ return; // Combination of states is not preserved on all platforms.
+ if (platformName == "xcb" && qgetenv("XDG_CURRENT_DESKTOP") != "KDE"
+ && qgetenv("XDG_CURRENT_DESKTOP") != "Unity")
+ return; // Not all window managers support state combinations.
+
+ QTest::newRow("Qt::WindowMaximized|Qt::WindowMinimized")
+ << (Qt::WindowMaximized | Qt::WindowMinimized);
+ QTest::newRow("Qt::WindowFullScreen|Qt::WindowMinimized")
+ << (Qt::WindowFullScreen | Qt::WindowMinimized);
+ QTest::newRow("Qt::WindowMaximized|Qt::WindowFullScreen")
+ << (Qt::WindowMaximized | Qt::WindowFullScreen);
+ QTest::newRow("Qt::WindowMaximized|Qt::WindowFullScreen|Qt::WindowMinimized")
+ << (Qt::WindowMaximized | Qt::WindowFullScreen | Qt::WindowMinimized);
+}
+
+void tst_QWidget_window::setWindowState()
+{
+ QFETCH(Qt::WindowStates, state);
+
+ // This tests make sure that the states are preserved when the window is shown.
+
+ QWidget w;
+ w.setWindowState(state);
+ QCOMPARE(w.windowState(), state);
+ w.show();
+ QCOMPARE(w.windowState(), state);
+ QCOMPARE(w.windowHandle()->windowStates(), state);
+ QTest::qWaitForWindowExposed(&w);
+ QTRY_COMPARE(w.windowState(), state);
+ QCOMPARE(w.windowHandle()->windowStates(), state);
+
+ // Minimizing keeps other states
+ w.showMinimized();
+ QCOMPARE(w.windowState(), state | Qt::WindowMinimized);
+ QTest::qWait(100);
+ QCOMPARE(w.windowState(), state | Qt::WindowMinimized);
+ QCOMPARE(w.windowHandle()->windowStates(), state | Qt::WindowMinimized);
+}
+
+void tst_QWidget_window::nativeShow()
+{
+ // Verify that a native widget can be shown using the QWindow::setVisible() API
+ QWidget w;
+ w.winId();
+ w.windowHandle()->setVisible(true);
+ QTest::qWaitForWindowExposed(&w);
+ QVERIFY(w.isVisible());
+
+ // ... and that we can hide it
+ w.windowHandle()->setVisible(false);
+ QTRY_VERIFY(!w.isVisible());
+}
+
class ResizedOnShowEventWidget : public QWidget
{
public: