diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qtsensors5/tst_qtsensors5.cpp | 1 | ||||
-rw-r--r-- | tests/auto/sensors2qmlapi/qtemplategestureplugin.cpp | 81 | ||||
-rw-r--r-- | tests/auto/sensors2qmlapi/qtemplategestureplugin.h | 65 | ||||
-rw-r--r-- | tests/auto/sensors2qmlapi/qtemplaterecognizer.cpp | 136 | ||||
-rw-r--r-- | tests/auto/sensors2qmlapi/qtemplaterecognizer.h | 93 | ||||
-rw-r--r-- | tests/auto/sensors2qmlapi/sensors2qmlapi.pro | 10 | ||||
-rw-r--r-- | tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp | 124 |
7 files changed, 508 insertions, 2 deletions
diff --git a/tests/auto/qtsensors5/tst_qtsensors5.cpp b/tests/auto/qtsensors5/tst_qtsensors5.cpp index 687bf2f..90c074c 100644 --- a/tests/auto/qtsensors5/tst_qtsensors5.cpp +++ b/tests/auto/qtsensors5/tst_qtsensors5.cpp @@ -102,6 +102,7 @@ private slots: QTest::newRow("TiltSensor 5.0") << "5.0" << "TiltSensor" << true; QTest::newRow("AmbientLightSensor 5.0") << "5.0" << "AmbientLightSensor" << true; QTest::newRow("ProximitySensor 5.0") << "5.0" << "ProximitySensor" << true; + QTest::newRow("SensorGesture 5.0") << "5.0" << "SensorGesture" << true; } void elements() diff --git a/tests/auto/sensors2qmlapi/qtemplategestureplugin.cpp b/tests/auto/sensors2qmlapi/qtemplategestureplugin.cpp new file mode 100644 index 0000000..5931889 --- /dev/null +++ b/tests/auto/sensors2qmlapi/qtemplategestureplugin.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QtPlugin> +#include <QStringList> +#include <QObject> + +#include "qtemplategestureplugin.h" +#include <qsensorgestureplugininterface.h> +#include <qsensorgesturemanager.h> +#include "qtemplaterecognizer.h" + + +QTemplateGesturePlugin::QTemplateGesturePlugin() +{ +} + +QTemplateGesturePlugin::~QTemplateGesturePlugin() +{ +} + +QStringList QTemplateGesturePlugin::supportedIds() const +{ + QStringList list; + list << "QtSensors.template" << "QtSensors.template1"; + return list; +} + + +QList <QSensorGestureRecognizer *> QTemplateGesturePlugin::createRecognizers() +{ + QList <QSensorGestureRecognizer *> recognizers; + + QSensorGestureRecognizer *sRec = new QTemplateGestureRecognizer(this); + recognizers.append(sRec); + sRec = new QTemplateGestureRecognizer1(this); + recognizers.append(sRec); + + return recognizers; +} + +Q_EXPORT_PLUGIN2(QTemplateGestureRecognizer, QTemplateGesturePlugin) + diff --git a/tests/auto/sensors2qmlapi/qtemplategestureplugin.h b/tests/auto/sensors2qmlapi/qtemplategestureplugin.h new file mode 100644 index 0000000..04e2662 --- /dev/null +++ b/tests/auto/sensors2qmlapi/qtemplategestureplugin.h @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef QTEMPLATEGESTUREPLUGIN_H +#define QTEMPLATEGESTUREPLUGIN_H + +#include <QObject> +#include <QStringList> + +#include <qsensorgestureplugininterface.h> + +class QTemplateGesturePlugin : public QObject, QSensorGesturePluginInterface +{ + Q_OBJECT + Q_INTERFACES(QSensorGesturePluginInterface) +public: + explicit QTemplateGesturePlugin(); + ~QTemplateGesturePlugin(); + + QList <QSensorGestureRecognizer *> createRecognizers(); + + QStringList gestureSignals() const; + QStringList supportedIds() const; + QString name() const { return "TemplateGestures"; } +}; + +#endif // QTEMPLATEGESTUREPLUGIN_H diff --git a/tests/auto/sensors2qmlapi/qtemplaterecognizer.cpp b/tests/auto/sensors2qmlapi/qtemplaterecognizer.cpp new file mode 100644 index 0000000..73bc162 --- /dev/null +++ b/tests/auto/sensors2qmlapi/qtemplaterecognizer.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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 <QDebug> +#include <QTimer> + +#include "qtemplaterecognizer.h" + +QTemplateGestureRecognizer::QTemplateGestureRecognizer(QObject *parent) + : QSensorGestureRecognizer(parent) +{ +} + +QTemplateGestureRecognizer::~QTemplateGestureRecognizer() +{ + +} + +void QTemplateGestureRecognizer::create() +{ + connect(&_timer,SIGNAL(timeout()),this,SLOT(timeout())); + _timer.setInterval(1000); +} + +bool QTemplateGestureRecognizer::start() +{ + Q_EMIT detected(id()); + _timer.start(); + return _timer.isActive(); +} + +bool QTemplateGestureRecognizer::stop() +{ + _timer.stop(); + return true; +} + + +bool QTemplateGestureRecognizer::isActive() +{ + return _timer.isActive(); +} + +QString QTemplateGestureRecognizer::id() const +{ + return QString("QtSensors.template"); +} + +void QTemplateGestureRecognizer::timeout() +{ + Q_EMIT detected(id()); +} + + +QTemplateGestureRecognizer1::QTemplateGestureRecognizer1(QObject *parent) + : QSensorGestureRecognizer(parent) +{ +} + +QTemplateGestureRecognizer1::~QTemplateGestureRecognizer1() +{ + +} + +void QTemplateGestureRecognizer1::create() +{ + connect(&_timer,SIGNAL(timeout()),this,SLOT(timeout())); + _timer.setInterval(500); +} + +bool QTemplateGestureRecognizer1::start() +{ + Q_EMIT detected(id()); + _timer.start(); + return _timer.isActive(); +} + +bool QTemplateGestureRecognizer1::stop() +{ + _timer.stop(); + return true; +} + + +bool QTemplateGestureRecognizer1::isActive() +{ + return _timer.isActive(); +} + +QString QTemplateGestureRecognizer1::id() const +{ + return QString("QtSensors.template1"); +} + +void QTemplateGestureRecognizer1::timeout() +{ + Q_EMIT detected(id()); +} diff --git a/tests/auto/sensors2qmlapi/qtemplaterecognizer.h b/tests/auto/sensors2qmlapi/qtemplaterecognizer.h new file mode 100644 index 0000000..1a4c419 --- /dev/null +++ b/tests/auto/sensors2qmlapi/qtemplaterecognizer.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** 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$ +** +****************************************************************************/ + +#ifndef QTEMPLATERECOGNIZER_H +#define QTEMPLATERECOGNIZER_H + +#include <QDebug> +#include <QtCore/QTimer> +#include <qsensorgesturerecognizer.h> + +class QTemplateGestureRecognizer : public QSensorGestureRecognizer +{ + Q_OBJECT +public: + + QTemplateGestureRecognizer(QObject *parent = 0); + ~QTemplateGestureRecognizer(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + +private slots: + void timeout(); + +private: + QTimer _timer; +}; + +class QTemplateGestureRecognizer1 : public QSensorGestureRecognizer +{ + Q_OBJECT +public: + + QTemplateGestureRecognizer1(QObject *parent = 0); + ~QTemplateGestureRecognizer1(); + + void create(); + + QString id() const; + bool start(); + bool stop(); + bool isActive(); + +private slots: + void timeout(); + +private: + QTimer _timer; +}; + +#endif // QTEMPLATERECOGNIZER_H diff --git a/tests/auto/sensors2qmlapi/sensors2qmlapi.pro b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro index acd8951..cdd9c02 100644 --- a/tests/auto/sensors2qmlapi/sensors2qmlapi.pro +++ b/tests/auto/sensors2qmlapi/sensors2qmlapi.pro @@ -9,7 +9,10 @@ DEPENDPATH += ./ SOURCES += tst_sensors2qmlapi.cpp \ ./../../../src/imports/sensors2/qsensor2ambientlight.cpp \ ./../../../src/imports/sensors2/qsensor2proximity.cpp \ - ./../../../src/imports/sensors2/qsensor2tilt.cpp + ./../../../src/imports/sensors2/qsensor2tilt.cpp \ + ./../../../src/imports/sensors2/qsensor2gesture.cpp \ + qtemplategestureplugin.cpp \ + qtemplaterecognizer.cpp HEADERS += qdeclaccelerometer.h \ qdeclambientlightsensor.h \ @@ -17,4 +20,7 @@ HEADERS += qdeclaccelerometer.h \ qbackends.h \ ./../../../src/imports/sensors2/qsensor2ambientlight.h \ ./../../../src/imports/sensors2/qsensor2proximity.h \ - ./../../../src/imports/sensors2/qsensor2tilt.h + ./../../../src/imports/sensors2/qsensor2tilt.h \ + ./../../../src/imports/sensors2/qsensor2gesture.h \ + qtemplategestureplugin.h \ + qtemplaterecognizer.h diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp index cc24d99..568019b 100644 --- a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp +++ b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp @@ -45,6 +45,10 @@ #include "../../../src/imports/sensors2/qsensor2ambientlight.h" #include "../../../src/imports/sensors2/qsensor2proximity.h" #include "../../../src/imports/sensors2/qsensor2tilt.h" +#include "../../../src/imports/sensors2/qsensor2gesture.h" +#include "qtemplategestureplugin.h" +#include "qtemplaterecognizer.h" +#include <qsensorgesturemanager.h> #include "qbackends.h" #include "qsensormanager.h" @@ -71,6 +75,7 @@ private slots: void testTiltUnit(); void testProximity(); void testAmbientLight(); + void testGesture(); protected: TestSensorPlugin _plugin; @@ -497,5 +502,124 @@ void tst_Sensors2QMLAPI::testTiltRunningMode() QCOMPARE(speed, QSensor2Tilt::Fast); } +void tst_Sensors2QMLAPI::testGesture() +{ + QTemplateGesturePlugin* plugin = new QTemplateGesturePlugin(); + QList <QSensorGestureRecognizer *> recognizers = plugin->createRecognizers(); + QSensorGestureManager manager; + + QSensor2Gesture* gs = new QSensor2Gesture(this); + gs->componentComplete(); + qDebug() << "QSensor2Gesture gestures:"; + qDebug() << gs->availableGestures(); + QSignalSpy spy_availableGesturesChanged(gs, SIGNAL(availableGesturesChanged())); + QSignalSpy spy_detected(gs, SIGNAL(detected(const QString))); + QSignalSpy spy_gesturesChanged(gs, SIGNAL(gesturesChanged())); + QSignalSpy spy_validGesturesChanged(gs, SIGNAL(validGesturesChanged())); + QSignalSpy spy_invalidGesturesChanged(gs, SIGNAL(invalidGesturesChanged())); + QSignalSpy spy_enabledChanged(gs, SIGNAL(enabledChanged())); + + //This flag is needed if you run this unit test with an alread installed template plugin + bool registered = false; + for (int i = 0; i < recognizers.count(); i++){ + registered = manager.registerSensorGestureRecognizer(recognizers[i]); + } + if (registered) { + QCOMPARE(spy_availableGesturesChanged.count(), 2); + } + + //check creation of a not known plugin + QCOMPARE(spy_invalidGesturesChanged.count(), 0); + QCOMPARE(spy_gesturesChanged.count(), 0); + gs->setGestures(QStringList() << "lollipop"); + QCOMPARE(spy_gesturesChanged.count(), 1); + QCOMPARE(spy_invalidGesturesChanged.count(), 1); + + //check creation of a known plugin + QCOMPARE(spy_validGesturesChanged.count(), 0); + QCOMPARE(spy_gesturesChanged.count(), 1); + spy_invalidGesturesChanged.clear(); + spy_validGesturesChanged.clear(); + gs->setGestures(QStringList() << "QtSensors.template"); + QCOMPARE(spy_gesturesChanged.count(), 2); + QCOMPARE(spy_invalidGesturesChanged.count(), 1); + QCOMPARE(spy_validGesturesChanged.count(), 1); + + //enable "QtSensors.template" + QCOMPARE(spy_enabledChanged.count(), 0); + QCOMPARE(spy_detected.count(), 0); + gs->setEnabled(true); + QCOMPARE(spy_enabledChanged.count(), 1); + QCOMPARE(spy_detected.count(), 1); + + //set gesture during running sensor should not emit gesture changed + spy_gesturesChanged.clear(); + gs->setGestures(QStringList() << "QtSensors.template2"); + QCOMPARE(spy_gesturesChanged.count(), 0); + + gs->setEnabled(false); + + QSensor2Gesture* gs1 = new QSensor2Gesture(this); + QSignalSpy spy1_detected(gs1, SIGNAL(detected(const QString))); + QSignalSpy spy1_gesturesChanged(gs1, SIGNAL(gesturesChanged())); + QSignalSpy spy1_validGesturesChanged(gs1, SIGNAL(validGesturesChanged())); + QSignalSpy spy1_invalidGesturesChanged(gs1, SIGNAL(invalidGesturesChanged())); + QSignalSpy spy1_enabledChanged(gs1, SIGNAL(enabledChanged())); + gs1->componentComplete(); + + //set enable = true without gesture should + gs1->setEnabled(true); + QCOMPARE(spy1_enabledChanged.count(), 1); + gs1->setEnabled(false); + spy1_enabledChanged.clear(); + + //reding gestures check if we get back an empty string list + QStringList gestures = gs1->gestures(); + QCOMPARE(gestures.count(), 0); + QStringList validgestures = gs1->validGestures(); + QCOMPARE(validgestures.count(), 0); + QStringList invalidgestures = gs1->invalidGestures(); + QCOMPARE(invalidgestures.count(), 0); + + //check types "QtSensors.template" "QtSensors.template1" "lollipop" + //expect valid 2 not available 1 + gestures << "QtSensors.template" << "QtSensors.template1" << "lollipop"; + gs1->setGestures(gestures); + gestures = gs1->gestures(); + QCOMPARE(gestures.count(), 3); + QCOMPARE(spy1_validGesturesChanged.count(), 1); + QCOMPARE(spy1_invalidGesturesChanged.count(), 1); + QCOMPARE(spy1_gesturesChanged.count(), 1); + //set same gesture again should not emit gesture changed + gs1->setGestures(gestures); + QCOMPARE(spy1_gesturesChanged.count(), 1); + + spy1_gesturesChanged.clear(); + gestures.clear(); + gs1->setGestures(gestures); + QCOMPARE(spy1_gesturesChanged.count(), 1); + + //enable "QtSensors.template" and "QtSensors.template1" + gestures << "QtSensors.template" << "QtSensors.template1"; + gs1->setEnabled(false); + gs1->setGestures(gestures); + spy1_enabledChanged.clear(); + spy1_detected.clear(); + gs1->setEnabled(true); + QCOMPARE(spy1_enabledChanged.count(), 1); + QCOMPARE(spy1_detected.count(), 2); + gs1->setEnabled(false); + + //check sensor shouldn't run until the componentComplete gets called + QSensor2Gesture* gs2 = new QSensor2Gesture(this); + QSignalSpy spy2_detected(gs2, SIGNAL(detected(const QString))); + gs2->setGestures(QStringList() << "QtSensors.template"); + gs2->setEnabled(true); + QCOMPARE(spy2_detected.count(), 0); + gs2->componentComplete(); + QCOMPARE(spy2_detected.count(), 1); +} + + QTEST_MAIN(tst_Sensors2QMLAPI) #include "tst_sensors2qmlapi.moc" |