diff options
Diffstat (limited to 'tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp')
-rw-r--r-- | tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp index cc24d990..568019b8 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" |