summaryrefslogtreecommitdiffstats
path: root/src/testlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib')
-rw-r--r--src/testlib/qtest_gui.h1
-rw-r--r--src/testlib/qtesttouch.h166
-rw-r--r--src/testlib/testlib.pro3
3 files changed, 169 insertions, 1 deletions
diff --git a/src/testlib/qtest_gui.h b/src/testlib/qtest_gui.h
index d389f1c..d317e85 100644
--- a/src/testlib/qtest_gui.h
+++ b/src/testlib/qtest_gui.h
@@ -46,6 +46,7 @@
#include <QtTest/qtest.h>
#include <QtTest/qtestevent.h>
#include <QtTest/qtestmouse.h>
+#include <QtTest/qtesttouch.h>
#include <QtTest/qtestkeyboard.h>
#include <QtGui/qicon.h>
diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h
new file mode 100644
index 0000000..ccfaa63
--- /dev/null
+++ b/src/testlib/qtesttouch.h
@@ -0,0 +1,166 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtTest module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** 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 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTESTTOUCH_H
+#define QTESTTOUCH_H
+
+#if 0
+// inform syncqt
+#pragma qt_no_master_include
+#endif
+
+#include <QtTest/qtest_global.h>
+#include <QtTest/qtestassert.h>
+#include <QtTest/qtestsystem.h>
+#include <QtTest/qtestspontaneevent.h>
+
+#include <QtCore/qmap.h>
+#include <QtGui/qevent.h>
+#include <QtGui/qwidget.h>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Test)
+
+namespace QTest
+{
+
+ class QTouchEventSequence
+ {
+ public:
+ ~QTouchEventSequence()
+ {
+ commit();
+ foreach(QTouchEvent::TouchPoint *pt, points)
+ delete pt;
+ points.clear();
+ }
+ QTouchEventSequence& press(int touchId, const QPoint &pt, QWidget *widget = 0)
+ {
+ touchPointStates |= Qt::TouchPointPressed;
+ QTouchEvent::TouchPoint *p = point(touchId);
+ p->setScreenPos(mapToScreen(widget, pt));
+ p->setState(Qt::TouchPointPressed);
+ return *this;
+ }
+ QTouchEventSequence& move(int touchId, const QPoint &pt, QWidget *widget = 0)
+ {
+ touchPointStates |= Qt::TouchPointMoved;
+ QTouchEvent::TouchPoint *p = point(touchId);
+ p->setScreenPos(mapToScreen(widget, pt));
+ p->setState(Qt::TouchPointMoved);
+ return *this;
+ }
+ QTouchEventSequence& release(int touchId, const QPoint &pt, QWidget *widget = 0)
+ {
+ touchPointStates |= Qt::TouchPointReleased;
+ QTouchEvent::TouchPoint *p = point(touchId);
+ p->setScreenPos(mapToScreen(widget, pt));
+ p->setState(Qt::TouchPointReleased);
+ return *this;
+ }
+ QTouchEventSequence& stationary(int touchId)
+ {
+ touchPointStates |= Qt::TouchPointStationary;
+ QTouchEvent::TouchPoint *p = point(touchId);
+ p->setState(Qt::TouchPointStationary);
+ return *this;
+ }
+
+ private:
+ QTouchEventSequence(QWidget *widget)
+ : targetWidget(widget)
+ {
+ }
+ QTouchEventSequence(const QTouchEventSequence &v);
+ void operator=(const QTouchEventSequence&);
+
+ QTouchEvent::TouchPoint* point(int touchId)
+ {
+ QTouchEvent::TouchPoint *pt = points.value(touchId, 0);
+ if (!pt) {
+ pt = new QTouchEvent::TouchPoint;
+ pt->setId(touchId);
+ points.insert(touchId, pt);
+ }
+ return pt;
+ }
+ QPoint mapToScreen(QWidget *widget, const QPoint &pt)
+ {
+ if (widget)
+ return widget->mapToGlobal(pt);
+ return targetWidget ? targetWidget->mapToGlobal(pt) : pt;
+ }
+ void commit()
+ {
+ QTouchEvent event(QEvent::RawTouch, Qt::NoModifier,
+ touchPointStates, points.values());
+ QSpontaneKeyEvent::setSpontaneous(&event);
+ if (targetWidget) {
+ if (!qApp->notify(targetWidget->window(), &event))
+ QTest::qWarn("Touch event not accepted by receiving widget");
+ targetWidget = 0;
+ } else {
+ if (!qApp->notify(qApp, &event))
+ QTest::qWarn("Touch event not accepted by receiving widget");
+ }
+ }
+
+ QMap<int, QTouchEvent::TouchPoint*> points;
+ QWidget *targetWidget;
+ Qt::TouchPointStates touchPointStates;
+ friend QTouchEventSequence touchEvent(QWidget*);
+ };
+
+ QTouchEventSequence touchEvent(QWidget *widget = 0)
+ {
+ return QTouchEventSequence(widget);
+ }
+
+}
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // QTESTTOUCH_H
diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro
index ae4f182..9740c21 100644
--- a/src/testlib/testlib.pro
+++ b/src/testlib/testlib.pro
@@ -20,7 +20,8 @@ HEADERS = qtest_global.h \
qtestxunitstreamer.h \
qtestxmlstreamer.h \
qtestlightxmlstreamer.h \
- qtestfilelogger.h
+ qtestfilelogger.h \
+ qtesttouch.h
SOURCES = qtestcase.cpp \
qtestlog.cpp \
qtesttable.cpp \