aboutsummaryrefslogtreecommitdiff
path: root/tests/ut_mswiperecognizer
diff options
context:
space:
mode:
authorMichal Guminiak <michal.guminiak@teleca.com>2010-08-03 10:13:57 +0200
committerDominik Kapusta <dominik.kapusta@teleca.com>2010-08-04 09:56:54 +0200
commit2be1d166f79e292d4c6d9634bc6d95b42d13acc1 (patch)
treeac9f4f0bb00405ad5242f07cbc3a80d5974e444f /tests/ut_mswiperecognizer
parentb7fe07c4ebc78ec32497a9f274982546ed58c614 (diff)
New: A redefined swipe recognizer, which allows one-finger swipes.
RevBy: Dominik, Michael Hasselmann Details: The swipe gesture recognizer available in Qt's sources was not really working in our environment, because for example it recognizes only "three-finger swipe" gesture. This implementation is based on the Qt's sources and the "flick" gesture ideas from input method project.
Diffstat (limited to 'tests/ut_mswiperecognizer')
-rw-r--r--tests/ut_mswiperecognizer/.gitignore1
-rw-r--r--tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp147
-rw-r--r--tests/ut_mswiperecognizer/ut_mswiperecognizer.h46
-rw-r--r--tests/ut_mswiperecognizer/ut_mswiperecognizer.pro16
4 files changed, 210 insertions, 0 deletions
diff --git a/tests/ut_mswiperecognizer/.gitignore b/tests/ut_mswiperecognizer/.gitignore
new file mode 100644
index 00000000..d7b3a22c
--- /dev/null
+++ b/tests/ut_mswiperecognizer/.gitignore
@@ -0,0 +1 @@
+ut_mswiperecognizer
diff --git a/tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp b/tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp
new file mode 100644
index 00000000..139fa15b
--- /dev/null
+++ b/tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp
@@ -0,0 +1,147 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it 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.
+**
+****************************************************************************/
+
+#include "ut_mswiperecognizer.h"
+#include "mswiperecognizer.h"
+#include "mswiperecognizer_p.h"
+
+#include "mswipegesture_p.h"
+
+#include <QGraphicsSceneMouseEvent>
+#include <QtTest/QtTest>
+
+
+Qt::GestureState currentGestureState = Qt::NoGesture;
+Qt::GestureState QGesture::state() const
+{
+ return currentGestureState;
+}
+
+void Ut_MSwipeRecognizer::init()
+{
+ recognizer = new MSwipeRecognizer();
+}
+
+void Ut_MSwipeRecognizer::cleanup()
+{
+ delete recognizer;
+}
+
+void Ut_MSwipeRecognizer::testCreateGesture()
+{
+ swipeGesture = static_cast<MSwipeGesture*>(recognizer->create(this));
+}
+
+void Ut_MSwipeRecognizer::testRecognize()
+{
+ QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
+ pressEvent.setPos(QPointF(0,0));
+ pressEvent.setScenePos(QPointF(0,0));
+ pressEvent.setScreenPos(QPoint(0,0));
+
+ QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
+ moveEvent.setPos(QPointF(55,0));
+ moveEvent.setScenePos(QPointF(55,0));
+ moveEvent.setScreenPos(QPoint(55,0));
+
+ QGestureRecognizer::Result currentState;
+ currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
+ QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
+
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
+
+}
+
+void Ut_MSwipeRecognizer::testFastTap()
+{
+
+ QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
+ pressEvent.setPos(QPointF(0,0));
+ pressEvent.setScenePos(QPointF(0,0));
+ pressEvent.setScreenPos(QPoint(0,0));
+
+ QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
+ releaseEvent.setPos(QPointF(0,0));
+ releaseEvent.setScenePos(QPointF(0,0));
+ releaseEvent.setScreenPos(QPoint(0,0));
+
+ QGestureRecognizer::Result currentState;
+ currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
+ QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
+
+ currentState = recognizer->recognize(swipeGesture, 0, &releaseEvent);
+ QCOMPARE( currentState, QGestureRecognizer::CancelGesture);
+}
+
+void Ut_MSwipeRecognizer::testTimedout()
+{
+ QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
+ pressEvent.setPos(QPointF(0,0));
+ pressEvent.setScenePos(QPointF(0,0));
+ pressEvent.setScreenPos(QPoint(0,0));
+
+ QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
+ moveEvent.setPos(QPointF(30,0));
+ moveEvent.setScenePos(QPointF(30,0));
+ moveEvent.setScreenPos(QPoint(30,0));
+
+ QGestureRecognizer::Result currentState;
+ currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
+ QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
+
+ swipeGesture->time = QTime().currentTime().addSecs(-3);
+
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ QCOMPARE( currentState, QGestureRecognizer::CancelGesture);
+
+}
+
+void Ut_MSwipeRecognizer::testZigzagged()
+{
+ QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
+ pressEvent.setPos(QPointF(0,0));
+ pressEvent.setScenePos(QPointF(0,0));
+ pressEvent.setScreenPos(QPoint(0,0));
+
+ QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
+ moveEvent.setPos(QPointF(55,0));
+ moveEvent.setScenePos(QPointF(55,0));
+ moveEvent.setScreenPos(QPoint(55,0));
+
+ QGestureRecognizer::Result currentState;
+ currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
+ QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
+
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
+
+ moveEvent.setPos(QPointF(-100,0));
+ moveEvent.setScenePos(QPointF(-100,0));
+ moveEvent.setScreenPos(QPoint(-100,0));
+
+ currentGestureState = Qt::GestureStarted;
+
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ QCOMPARE( currentState, QGestureRecognizer::CancelGesture);
+
+}
+
+QTEST_APPLESS_MAIN(Ut_MSwipeRecognizer)
+
diff --git a/tests/ut_mswiperecognizer/ut_mswiperecognizer.h b/tests/ut_mswiperecognizer/ut_mswiperecognizer.h
new file mode 100644
index 00000000..cd72b1f7
--- /dev/null
+++ b/tests/ut_mswiperecognizer/ut_mswiperecognizer.h
@@ -0,0 +1,46 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it 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.
+**
+****************************************************************************/
+
+#ifndef UT_MSWIPERECOGNIZER_H
+#define UT_MSWIPERECOGNIZER_H
+
+#include <QObject>
+
+class MSwipeRecognizer;
+class MSwipeGesture;
+
+class Ut_MSwipeRecognizer : public QObject
+{
+ Q_OBJECT
+
+private:
+ MSwipeRecognizer* recognizer;
+ MSwipeGesture* swipeGesture;
+private slots:
+ void init();
+ void cleanup();
+
+ void testCreateGesture();
+ void testRecognize();
+ void testFastTap();
+ void testTimedout();
+ void testZigzagged();
+};
+
+#endif // UT_MSWIPERECOGNIZER_H
diff --git a/tests/ut_mswiperecognizer/ut_mswiperecognizer.pro b/tests/ut_mswiperecognizer/ut_mswiperecognizer.pro
new file mode 100644
index 00000000..bcc331a5
--- /dev/null
+++ b/tests/ut_mswiperecognizer/ut_mswiperecognizer.pro
@@ -0,0 +1,16 @@
+include(../common_top.pri)
+INCLUDEPATH += $$MSRCDIR/corelib/events
+TARGET = ut_mswiperecognizer
+
+# unit test and unit classes
+SOURCES += \
+ ut_mswiperecognizer.cpp \
+ $$MSRCDIR/corelib/events/mswiperecognizer.cpp \
+ $$MSRCDIR/corelib/events/mswipegesture.cpp \
+
+# unit test and unit classes
+HEADERS += \
+ ut_mswiperecognizer.h \
+ $$MSRCDIR/corelib/events/mswipegesture_p.h \
+
+include(../common_bot.pri)