summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-02-15 21:19:50 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2018-02-15 21:19:50 +0000
commit1ef03f69e8416a70efd14df09e1231ce0bc00ea9 (patch)
tree7edc868dff999b4f9123bf87e92c9a7cb72e9db1 /tests
parent23eab78f510a9cfb050980f522dc23409e23fbdb (diff)
parentbb0fec8057dd11c359bfcb4aefb66d9b210f52a6 (diff)
Merge "Merge remote-tracking branch 'origin/5.10' into 5.11" into refs/staging/5.11
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp64
-rw-r--r--tests/auto/gui/image/qmovie/tst_qmovie.cpp10
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp76
-rw-r--r--tests/manual/touchGraphicsItem/main.cpp163
-rw-r--r--tests/manual/touchGraphicsItem/touchGraphicsItem.pro5
5 files changed, 314 insertions, 4 deletions
diff --git a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp
index 15a39b62c0..76efa008f7 100644
--- a/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp
+++ b/tests/auto/corelib/kernel/qwineventnotifier/tst_qwineventnotifier.cpp
@@ -29,8 +29,11 @@
#include <QtTest/QtTest>
#include <qwineventnotifier.h>
#include <qtimer.h>
+#include <qvarlengtharray.h>
+#include <qvector.h>
#include <qt_windows.h>
+#include <algorithm>
#include <memory>
class tst_QWinEventNotifier : public QObject
@@ -44,6 +47,8 @@ private slots:
void simple_data();
void simple();
void manyNotifiers();
+ void disableNotifiersInActivatedSlot_data();
+ void disableNotifiersInActivatedSlot();
private:
HANDLE simpleHEvent;
@@ -109,9 +114,6 @@ public:
this, &EventWithNotifier::onNotifierActivated);
notifier.setHandle(CreateEvent(0, TRUE, FALSE, 0));
notifier.setEnabled(true);
-
- static int nextIndex = 0;
- idx = nextIndex++;
}
~EventWithNotifier()
@@ -122,6 +124,7 @@ public:
HANDLE eventHandle() const { return notifier.handle(); }
int numberOfTimesActivated() const { return activatedCount; }
+ void setEnabled(bool b) { notifier.setEnabled(b); }
signals:
void activated();
@@ -137,7 +140,6 @@ public slots:
private:
QWinEventNotifier notifier;
int activatedCount = 0;
- int idx = 0;
};
void tst_QWinEventNotifier::manyNotifiers()
@@ -184,6 +186,60 @@ void tst_QWinEventNotifier::manyNotifiers()
}));
}
+using Indices = QVector<int>;
+
+void tst_QWinEventNotifier::disableNotifiersInActivatedSlot_data()
+{
+ QTest::addColumn<int>("count");
+ QTest::addColumn<Indices>("notifiersToSignal");
+ QTest::addColumn<Indices>("notifiersToDisable");
+ QTest::addColumn<bool>("deleteNotifiers");
+ QTest::newRow("disable_signaled") << 3 << Indices{1} << Indices{1} << false;
+ QTest::newRow("disable_signaled2") << 3 << Indices{1, 2} << Indices{1} << false;
+ QTest::newRow("disable_before_signaled") << 3 << Indices{1} << Indices{0, 1} << false;
+ QTest::newRow("disable_after_signaled") << 3 << Indices{1} << Indices{1, 2} << false;
+ QTest::newRow("delete_signaled") << 3 << Indices{1} << Indices{1} << true;
+ QTest::newRow("delete_before_signaled1") << 3 << Indices{1} << Indices{0} << true;
+ QTest::newRow("delete_before_signaled2") << 3 << Indices{1} << Indices{0, 1} << true;
+ QTest::newRow("delete_before_signaled3") << 4 << Indices{3, 1} << Indices{0, 1} << true;
+ QTest::newRow("delete_after_signaled1") << 3 << Indices{1} << Indices{1, 2} << true;
+ QTest::newRow("delete_after_signaled2") << 4 << Indices{1, 3} << Indices{1, 2} << true;
+ QTest::newRow("delete_after_signaled3") << 5 << Indices{1} << Indices{1, 4} << true;
+}
+
+void tst_QWinEventNotifier::disableNotifiersInActivatedSlot()
+{
+ QFETCH(int, count);
+ QFETCH(Indices, notifiersToSignal);
+ QFETCH(Indices, notifiersToDisable);
+ QFETCH(bool, deleteNotifiers);
+
+ QVarLengthArray<std::unique_ptr<EventWithNotifier>, 10> events(count);
+ for (int i = 0; i < count; ++i)
+ events[i].reset(new EventWithNotifier);
+
+ auto isActivatedOrNull = [&events](int i) {
+ return !events.at(i) || events.at(i)->numberOfTimesActivated() > 0;
+ };
+
+ for (auto &e : events) {
+ connect(e.get(), &EventWithNotifier::activated, [&]() {
+ for (int i : notifiersToDisable) {
+ if (deleteNotifiers)
+ events[i].reset();
+ else
+ events.at(i)->setEnabled(false);
+ }
+ if (std::all_of(notifiersToSignal.begin(), notifiersToSignal.end(), isActivatedOrNull))
+ QTimer::singleShot(0, &QTestEventLoop::instance(), SLOT(exitLoop()));
+ });
+ }
+ for (int i : notifiersToSignal)
+ SetEvent(events.at(i)->eventHandle());
+ QTestEventLoop::instance().enterLoop(30);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+}
+
QTEST_MAIN(tst_QWinEventNotifier)
#include "tst_qwineventnotifier.moc"
diff --git a/tests/auto/gui/image/qmovie/tst_qmovie.cpp b/tests/auto/gui/image/qmovie/tst_qmovie.cpp
index bcaa759faa..4e9e9b8115 100644
--- a/tests/auto/gui/image/qmovie/tst_qmovie.cpp
+++ b/tests/auto/gui/image/qmovie/tst_qmovie.cpp
@@ -170,6 +170,16 @@ void tst_QMovie::playMovie()
QCOMPARE(movie.state(), QMovie::NotRunning);
QCOMPARE(movie.frameCount(), frameCount);
#endif
+
+ movie.stop();
+ QSignalSpy finishedSpy(&movie, &QMovie::finished);
+ movie.setSpeed(0);
+ movie.start();
+ QCOMPARE(movie.state(), QMovie::Running);
+ QTestEventLoop::instance().enterLoop(2);
+ QCOMPARE(finishedSpy.count(), 0);
+ QCOMPARE(movie.state(), QMovie::Running);
+ QCOMPARE(movie.currentFrameNumber(), 0);
}
void tst_QMovie::jumpToFrame_data()
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
index 3b340d06ab..fe8571abf1 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp
@@ -254,6 +254,7 @@ private slots:
void zeroScale();
void focusItemChangedSignal();
void minimumRenderSize();
+ void checkTouchPointsEllipseDiameters();
// task specific tests below me
void task139710_bspTreeCrash();
@@ -4764,6 +4765,81 @@ void tst_QGraphicsScene::minimumRenderSize()
QVERIFY(smallChild->repaints > smallerGrandChild->repaints);
}
+class TouchItem : public QGraphicsRectItem
+{
+public:
+ TouchItem() : QGraphicsRectItem(QRectF(-10, -10, 20, 20)),
+ seenTouch(false)
+ {
+ setAcceptTouchEvents(true);
+ setFlag(QGraphicsItem::ItemIgnoresTransformations);
+ }
+ bool seenTouch;
+ QList<QTouchEvent::TouchPoint> touchPoints;
+protected:
+ bool sceneEvent(QEvent *event) override
+ {
+ switch (event->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ seenTouch = true;
+ touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ event->accept();
+ return true;
+ default:
+ break;
+ }
+ return QGraphicsRectItem::sceneEvent(event);
+ }
+};
+
+void tst_QGraphicsScene::checkTouchPointsEllipseDiameters()
+{
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+ scene.setSceneRect(1, 1, 198, 198);
+ view.scale(1.5, 1.5);
+ view.setFocus();
+ TouchItem *rect = new TouchItem;
+ scene.addItem(rect);
+ view.show();
+ QApplication::setActiveWindow(&view);
+ QVERIFY(QTest::qWaitForWindowActive(&view));
+
+ const QSizeF ellipseDiameters(10.0, 10.0);
+ QTouchEvent::TouchPoint touchPoint(0);
+ touchPoint.setState(Qt::TouchPointPressed);
+ touchPoint.setPos(view.mapFromScene(rect->mapToScene(rect->boundingRect().center())));
+ touchPoint.setScreenPos(view.mapToGlobal(touchPoint.pos().toPoint()));
+ touchPoint.setEllipseDiameters(ellipseDiameters);
+
+ QList<QTouchEvent::TouchPoint> touchPoints = { touchPoint };
+
+ QTouchDevice *testDevice = QTest::createTouchDevice(QTouchDevice::TouchPad);
+ QTouchEvent touchEvent(QEvent::TouchBegin,
+ testDevice,
+ Qt::NoModifier,
+ Qt::TouchPointPressed,
+ touchPoints);
+ QApplication::sendEvent(view.viewport(), &touchEvent);
+ QVERIFY(rect->seenTouch);
+ QVERIFY(rect->touchPoints.size() == 1);
+ QCOMPARE(ellipseDiameters, rect->touchPoints.first().ellipseDiameters());
+
+ rect->seenTouch = false;
+ rect->touchPoints.clear();
+ QTouchEvent touchUpdateEvent(QEvent::TouchUpdate,
+ testDevice,
+ Qt::NoModifier,
+ Qt::TouchPointMoved,
+ touchPoints);
+ QApplication::sendEvent(view.viewport(), &touchEvent);
+ QVERIFY(rect->seenTouch);
+ QVERIFY(rect->touchPoints.size() == 1);
+ QCOMPARE(ellipseDiameters, rect->touchPoints.first().ellipseDiameters());
+}
+
void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache()
{
QGraphicsScene scene;
diff --git a/tests/manual/touchGraphicsItem/main.cpp b/tests/manual/touchGraphicsItem/main.cpp
new file mode 100644
index 0000000000..7afadc7edd
--- /dev/null
+++ b/tests/manual/touchGraphicsItem/main.cpp
@@ -0,0 +1,163 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 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:BSD$
+** 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.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtWidgets>
+
+class TouchableItem : public QGraphicsRectItem
+{
+public:
+ TouchableItem() : QGraphicsRectItem(50, 50, 400, 400)
+ {
+ setBrush(Qt::yellow);
+ setAcceptTouchEvents(true);
+ }
+protected:
+ bool sceneEvent(QEvent *e)
+ {
+ const bool ret = QGraphicsRectItem::sceneEvent(e);
+ switch (e->type()) {
+ case QEvent::TouchBegin:
+ case QEvent::TouchUpdate:
+ case QEvent::TouchEnd:
+ {
+ QTouchEvent *te = static_cast<QTouchEvent *>(e);
+ for (const QTouchEvent::TouchPoint &tp : te->touchPoints()) {
+ QGraphicsEllipseItem *diameterItem = nullptr;
+ QSizeF ellipse = tp.ellipseDiameters();
+ if (ellipse.isNull()) {
+ ellipse = QSizeF(5, 5);
+ } else {
+ diameterItem = new QGraphicsEllipseItem(QRectF(tp.pos().x() - ellipse.width() / 2, tp.pos().y() - ellipse.height() / 2,
+ ellipse.width(), ellipse.height()), this);
+ diameterItem->setPen(QPen(Qt::red));
+ diameterItem->setBrush(QBrush(Qt::red));
+ if (ellipse.width() > qreal(2) && ellipse.height() > qreal(2))
+ ellipse.scale(ellipse.width() - 2, ellipse.height() - 2, Qt::IgnoreAspectRatio);
+ }
+ QGraphicsItem *parent = diameterItem ? static_cast<QGraphicsItem *>(diameterItem) : static_cast<QGraphicsItem *>(this);
+ QGraphicsEllipseItem *ellipseItem = new QGraphicsEllipseItem(QRectF(tp.pos().x() - ellipse.width() / 2,
+ tp.pos().y() - ellipse.height() / 2,
+ ellipse.width(), ellipse.height()), parent);
+ ellipseItem->setPen(QPen(Qt::blue));
+ ellipseItem->setBrush(QBrush(Qt::blue));
+ }
+ te->accept();
+ return true;
+ }
+ default:
+ break;
+ }
+ return ret;
+ }
+};
+
+int main(int argc, char **argv)
+{
+ QApplication a(argc, argv);
+ QMainWindow mw;
+ QWidget *w = new QWidget;
+ QVBoxLayout *vbox = new QVBoxLayout;
+ vbox->addWidget(new QLabel("The blue ellipses should indicate touch point contact patches"));
+ qDebug() << "Touch devices:";
+ for (const QTouchDevice *device : QTouchDevice::devices()) {
+ QString result;
+ QTextStream str(&result);
+ str << (device->type() == QTouchDevice::TouchScreen ? "TouchScreen" : "TouchPad")
+ << " \"" << device->name() << "\", max " << device->maximumTouchPoints()
+ << " touch points, capabilities:";
+ const QTouchDevice::Capabilities capabilities = device->capabilities();
+ if (capabilities & QTouchDevice::Position)
+ str << " Position";
+ if (capabilities & QTouchDevice::Area)
+ str << " Area";
+ if (capabilities & QTouchDevice::Pressure)
+ str << " Pressure";
+ if (capabilities & QTouchDevice::Velocity)
+ str << " Velocity";
+ if (capabilities & QTouchDevice::RawPositions)
+ str << " RawPositions";
+ if (capabilities & QTouchDevice::NormalizedPosition)
+ str << " NormalizedPosition";
+ if (capabilities & QTouchDevice::MouseEmulation)
+ str << " MouseEmulation";
+ vbox->addWidget(new QLabel(result));
+ qDebug() << " " << result;
+ }
+ QGraphicsView *view = new QGraphicsView;
+ view->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
+ QGraphicsScene *scene = new QGraphicsScene(0, 0, 500, 500);
+ TouchableItem *touchableItem = new TouchableItem;
+ scene->addItem(touchableItem);
+ view->setScene(scene);
+ vbox->addWidget(view);
+ w->setLayout(vbox);
+ mw.setCentralWidget(w);
+ QMenu *menu = mw.menuBar()->addMenu("Menu");
+ QAction *clear = new QAction("Clear");
+ QObject::connect(clear, &QAction::triggered, [=]() {
+ qDeleteAll(touchableItem->childItems());
+ });
+ menu->addAction(clear);
+ QAction *ignoreTransform = new QAction("Ignore transformations");
+ QObject::connect(ignoreTransform, &QAction::triggered, [=]() {
+ view->scale(1.5, 1.5);
+ touchableItem->setFlag(QGraphicsItem::ItemIgnoresTransformations);
+ });
+ menu->addAction(ignoreTransform);
+ QAction *quit = new QAction("Quit");
+ quit->setShortcut(QKeySequence::Quit);
+ QObject::connect(quit, &QAction::triggered, &QApplication::quit);
+ menu->addAction(quit);
+ mw.show();
+
+ return a.exec();
+}
+
+
diff --git a/tests/manual/touchGraphicsItem/touchGraphicsItem.pro b/tests/manual/touchGraphicsItem/touchGraphicsItem.pro
new file mode 100644
index 0000000000..67799ce9c4
--- /dev/null
+++ b/tests/manual/touchGraphicsItem/touchGraphicsItem.pro
@@ -0,0 +1,5 @@
+QT+=widgets
+TEMPLATE = app
+TARGET = touchGraphicsItem
+INCLUDEPATH += .
+SOURCES += main.cpp