summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@nokia.com>2012-03-12 14:54:21 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-14 00:54:08 +0100
commit43e4ebecfbd672c887f8f30582c6df45b8065523 (patch)
treeceb1d53adbf164235e80f84b5d1cbcd0919f701d /tests
parent8f838dce6ee726297230666a9ddfa58c75138665 (diff)
downloadqtsensors-43e4ebecfbd672c887f8f30582c6df45b8065523.tar.gz
add some testing for sensorgestureplugins, however feeble.
Change-Id: I4758f401cbf577b2ac7ba772f4897e6334f22900 Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/auto.pro2
-rw-r--r--tests/auto/qsensorgestureplugins/qsensorgestureplugins.pro9
-rw-r--r--tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp222
-rw-r--r--tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp31
4 files changed, 259 insertions, 5 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro
index b3042af..8bb79fe 100644
--- a/tests/auto/auto.pro
+++ b/tests/auto/auto.pro
@@ -5,3 +5,5 @@ SUBDIRS += sensors2qmlapi
SUBDIRS += legacy_sensors
SUBDIRS += qtsensors5
SUBDIRS += qsensorgestures
+SUBDIRS += qsensorgestureplugins
+
diff --git a/tests/auto/qsensorgestureplugins/qsensorgestureplugins.pro b/tests/auto/qsensorgestureplugins/qsensorgestureplugins.pro
new file mode 100644
index 0000000..a0ad023
--- /dev/null
+++ b/tests/auto/qsensorgestureplugins/qsensorgestureplugins.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+TARGET = tst_qsensorgesturepluginstest
+!no_system_tests:CONFIG += testcase
+
+QT += core testlib sensors
+QT -= gui
+
+SOURCES += tst_qsensorgesturepluginstest.cpp
+
diff --git a/tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp b/tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp
new file mode 100644
index 0000000..3fb139b
--- /dev/null
+++ b/tests/auto/qsensorgestureplugins/tst_qsensorgesturepluginstest.cpp
@@ -0,0 +1,222 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the QtSensors module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** 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.1, 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.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QString>
+#include <QtTest/QtTest>
+
+#include <QVariant>
+#include <QSignalSpy>
+
+#include <qsensorgesture.h>
+#include <qsensorgesturemanager.h>
+
+#include <qsensorgesturerecognizer.h>
+#include <qsensorgestureplugininterface.h>
+
+class Tst_qsensorgesturePluginsTest : public QObject
+{
+ Q_OBJECT
+
+public:
+ Tst_qsensorgesturePluginsTest();
+
+private Q_SLOTS:
+
+ void tst_sensor_plugins_shake();
+ void tst_sensor_plugins_qtsensors_data();
+ void tst_sensor_plugins_qtsensors();
+ void tst_sensor_plugins_qtsensors_all();
+
+};
+
+Tst_qsensorgesturePluginsTest::Tst_qsensorgesturePluginsTest()
+{
+}
+
+void Tst_qsensorgesturePluginsTest::tst_sensor_plugins_shake()
+{
+
+ QSensorGestureManager manager;
+ QVERIFY(manager.gestureIds().contains("QtSensors.shake"));
+
+ QSensorGestureRecognizer *recognizer = manager.sensorGestureRecognizer("QtSensors.shake");
+
+ QCOMPARE(recognizer->isActive(), false);
+
+ QTest::ignoreMessage(QtWarningMsg, "Not starting. Gesture Recognizer not initialized ");
+ recognizer->startBackend();
+ QCOMPARE(recognizer->isActive(), false);
+
+ QTest::ignoreMessage(QtWarningMsg, "Not stopping. Gesture Recognizer not initialized ");
+ recognizer->stopBackend();
+ QCOMPARE(recognizer->isActive(), false);
+
+ QScopedPointer<QSensorGesture> gesture(new QSensorGesture(QStringList() << "QtSensors.shake"));
+
+ QCOMPARE(gesture->isActive(),false);
+ QCOMPARE(gesture->validIds(), QStringList() << "QtSensors.shake");
+
+ QCOMPARE(QStringList() << recognizer->id(), gesture->validIds());
+
+ gesture->startDetection();
+ QCOMPARE(gesture->isActive(),true);
+ QCOMPARE(recognizer->isActive(), true);
+
+ gesture->stopDetection();
+ QCOMPARE(recognizer->isActive(), false);
+}
+
+void Tst_qsensorgesturePluginsTest::tst_sensor_plugins_qtsensors_data()
+{
+ QTest::addColumn<QString>("gestureId");
+
+ QTest::newRow("QtSensors.cover") << "QtSensors.cover";
+ QTest::newRow("QtSensors.doubletap") << "QtSensors.doubletap";
+ QTest::newRow("QtSensors.hover") << "QtSensors.hover";
+ QTest::newRow("QtSensors.hover") << "QtSensors.hover";
+ QTest::newRow("QtSensors.shake2") << "QtSensors.shake2";
+ QTest::newRow("QtSensors.slam") << "QtSensors.slam";
+ QTest::newRow("QtSensors.turnover") << "QtSensors.turnover";
+ QTest::newRow("QtSensors.twist") << "QtSensors.twist";
+ QTest::newRow("QtSensors.whip") << "QtSensors.whip";
+}
+
+void Tst_qsensorgesturePluginsTest::tst_sensor_plugins_qtsensors()
+{
+ QFETCH(QString, gestureId);
+
+ QSensorGestureManager manager;
+
+ QVERIFY(manager.gestureIds().contains(gestureId));
+
+ QScopedPointer<QSensorGesture> gesture(new QSensorGesture(QStringList() << gestureId));
+ QScopedPointer<QSensorGesture> gesture2(new QSensorGesture(QStringList() << gestureId));
+
+ QCOMPARE(gesture->isActive(),false);
+ QCOMPARE(gesture->validIds(), QStringList() << gestureId);
+
+ QSensorGestureRecognizer *recognizer = manager.sensorGestureRecognizer(gestureId);
+
+ QCOMPARE(QStringList() << recognizer->id(), gesture->validIds());
+
+ QCOMPARE(QStringList() << QStringList(), gesture->invalidIds());
+
+ QVERIFY(recognizer->isActive() == false);
+ QVERIFY(gesture->isActive() == false);
+ QVERIFY(gesture2->isActive() == false);
+
+ gesture->startDetection();
+
+ QVERIFY(gesture->isActive() == true);
+ QVERIFY(gesture2->isActive() == false);
+
+ if (gestureId.contains("cover") || gestureId.contains("doubletap") || gestureId.contains("turnover")) {
+ // prox and tap dont work yet
+ QEXPECT_FAIL("", QString("fail ok for: " + gestureId).toLocal8Bit(), Continue);
+ }
+ QVERIFY(recognizer->isActive() == true);
+
+ gesture2->startDetection();
+
+ QVERIFY(gesture->isActive() == true);
+ QVERIFY(gesture2->isActive() == true);
+ if (gestureId.contains("cover") || gestureId.contains("doubletap") || gestureId.contains("turnover")) {
+ // prox and tap dont work yet
+ QEXPECT_FAIL("", QString("fail ok for: " + gestureId).toLocal8Bit(), Continue);
+ }
+ QVERIFY(recognizer->isActive() == true);
+
+ gesture2->stopDetection();
+
+ QVERIFY(gesture->isActive() == true);
+ QVERIFY(gesture2->isActive() == false);
+ if (gestureId.contains("cover") || gestureId.contains("doubletap") || gestureId.contains("turnover")) {
+ // prox and tap dont work yet
+ QEXPECT_FAIL("", QString("fail ok for: " + gestureId).toLocal8Bit(), Continue);
+ }
+ QVERIFY(recognizer->isActive() == true);
+
+ gesture->stopDetection();
+
+ QVERIFY(gesture->isActive() == false);
+ QVERIFY(gesture2->isActive() == false);
+ QVERIFY(recognizer->isActive() == false);
+
+
+ QVERIFY(recognizer->gestureSignals().count() > 1);
+ QVERIFY(recognizer->gestureSignals().contains("detected(QString)"));
+
+}
+
+void Tst_qsensorgesturePluginsTest::tst_sensor_plugins_qtsensors_all()
+{
+ QStringList list;
+ list << "QtSensors.cover";
+ list << "QtSensors.doubletap";
+ list << "QtSensors.hover";
+ list << "QtSensors.pickup";
+ list << "QtSensors.shake2";
+ list << "QtSensors.slam";
+ list << "QtSensors.turnover";
+ list << "QtSensors.twist";
+ list << "QtSensors.whip";
+
+ QSensorGestureManager manager;
+
+ QScopedPointer<QSensorGesture> gesture(new QSensorGesture(list));
+ QVERIFY(gesture->invalidIds().count() == 0);
+ QVERIFY(gesture->validIds().count() == 9);
+ QVERIFY(gesture->gestureSignals().count() == 14);
+
+ gesture->startDetection();
+ QVERIFY(gesture->isActive());
+
+ QSensorGestureRecognizer *recognizer = manager.sensorGestureRecognizer("QtSensors.turnover");
+ recognizer->stopBackend();
+ QVERIFY(!recognizer->isActive());
+ QVERIFY(gesture->isActive());
+
+}
+
+
+QTEST_MAIN(Tst_qsensorgesturePluginsTest);
+
+#include "tst_qsensorgesturepluginstest.moc"
diff --git a/tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp b/tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp
index 7e3b943..bd7d335 100644
--- a/tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp
+++ b/tests/auto/qsensorgestures/tst_qsensorgesturetest.cpp
@@ -121,6 +121,7 @@ public:
Tst_qsensorgestureTest();
private Q_SLOTS:
+ void tst_sensor_gesture_notinitialized();
void tst_recognizer_dup(); //comes first to weed out messages
@@ -143,6 +144,7 @@ private Q_SLOTS:
void shakeDetected(const QString &);
+
private:
QString currentSignal;
};
@@ -153,16 +155,15 @@ Tst_qsensorgestureTest::Tst_qsensorgestureTest()
void Tst_qsensorgestureTest::tst_recognizer_dup()
{
+ QStringList idList;
{
- QStringList idList;
// QTest::ignoreMessage(QtWarningMsg, "\"QtSensors.test.dup\" from the plugin \"TestGesturesDup\" is already known. ");
QSensorGestureManager manager;
idList = manager.gestureIds();
for (int i = 0; i < idList.count(); i++) {
- // if (idList.at(i) == "QtSensors.test.dup")
-
- // QTest::ignoreMessage(QtWarningMsg, "Ignoring recognizer \"QtSensors.test.dup\" from plugin \"TestGesturesDup\" because it is already registered ");
+ if (idList.at(i) == "QtSensors.test.dup")
+ QTest::ignoreMessage(QtWarningMsg, "Ignoring recognizer \"QtSensors.test.dup\" from plugin \"TestGesturesDup\" because it is already registered ");
QStringList recognizerSignalsList = manager.recognizerSignals(idList.at(i));
QVERIFY(!recognizerSignalsList.contains("QtSensors.test2"));
@@ -521,7 +522,7 @@ void Tst_qsensorgestureTest::tst_sensorgesture_noid()
QVERIFY(gesture->validIds().isEmpty());
QCOMPARE(gesture->invalidIds(), QStringList() << "QtSensors.noid");
-// QTest::ignoreMessage(QtWarningMsg, "QSignalSpy: No such signal: 'detected(QString)'");
+ QTest::ignoreMessage(QtWarningMsg, "QSignalSpy: No such signal: 'detected(QString)'");
QSignalSpy spy_gesture(gesture.data(), SIGNAL(detected(QString)));
QCOMPARE(spy_gesture.count(),0);
@@ -599,6 +600,26 @@ void Tst_qsensorgestureTest::shakeDetected(const QString &type)
QCOMPARE(type,currentSignal);
}
+void Tst_qsensorgestureTest::tst_sensor_gesture_notinitialized()
+{
+ QTest::ignoreMessage(QtWarningMsg, "\"QtSensors.test.dup\" from the plugin \"TestGesturesDup\" is already known. ");
+ QSensorGestureManager manager;
+ QSensorGestureRecognizer *recognizer = manager.sensorGestureRecognizer("QtSensors.test");
+
+ QTest::ignoreMessage(QtWarningMsg, "Not starting. Gesture Recognizer not initialized ");
+ recognizer->startBackend();
+ QVERIFY(recognizer->isActive() == false);
+
+ QTest::ignoreMessage(QtWarningMsg, "Not stopping. Gesture Recognizer not initialized ");
+ recognizer->stopBackend();
+ QVERIFY(recognizer->isActive() == false);
+
+ recognizer->createBackend();
+ QVERIFY(recognizer->isActive() == false);
+
+}
+
+
QTEST_MAIN(Tst_qsensorgestureTest);
#include "tst_qsensorgesturetest.moc"