diff options
author | Xizhi Zhu <xizhi.zhu@nokia.com> | 2011-07-01 10:13:44 +0300 |
---|---|---|
committer | Xizhi Zhu <xizhi.zhu@nokia.com> | 2011-07-01 11:09:43 +0300 |
commit | d8fb85f96701da66d5acc1ce02d1dac269ca5e41 (patch) | |
tree | 8a776517fdfdff27c1d97d817a698ed73db9e62e /tests |
Initial commit of modularized QtFeedback.
TODO:
1) Remove qmobilitypluginsearch.h
2) Fix auto tests.
Diffstat (limited to 'tests')
32 files changed, 2182 insertions, 0 deletions
diff --git a/tests/auto/auto.pri b/tests/auto/auto.pri new file mode 100644 index 0000000..9c526c2 --- /dev/null +++ b/tests/auto/auto.pri @@ -0,0 +1,4 @@ +TEMPLATE = app +CONFIG += qt debug warn_on console depend_includepath testcase + +qtAddLibrary(QtTest) diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 0000000..da1c2ae --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,13 @@ +TEMPLATE = subdirs +SUBDIRS += qfeedbackactuator \ + qfeedbackhapticseffect \ + qfeedbackplugin \ + qfeedbacknoplugins + +# this is the same condition that enables the mmk plugin +equals(QT_MAJOR_VERSION, 4) : greaterThan(QT_MINOR_VERSION, 6):contains(mobility_modules,multimedia): SUBDIRS += qfeedbackmmk + +contains(QT_CONFIG, declarative) { + SUBDIRS += qdeclarativefeedback +} + diff --git a/tests/auto/qdeclarativefeedback/data/actuator.qml b/tests/auto/qdeclarativefeedback/data/actuator.qml new file mode 100644 index 0000000..f0d314d --- /dev/null +++ b/tests/auto/qdeclarativefeedback/data/actuator.qml @@ -0,0 +1,5 @@ +import QtMobility.feedback 1.1 + +Actuator { + enabled: false +}
\ No newline at end of file diff --git a/tests/auto/qdeclarativefeedback/data/fileeffect.qml b/tests/auto/qdeclarativefeedback/data/fileeffect.qml new file mode 100644 index 0000000..7857e2d --- /dev/null +++ b/tests/auto/qdeclarativefeedback/data/fileeffect.qml @@ -0,0 +1,6 @@ +import QtMobility.feedback 1.1 + +FileEffect { + loaded: false + source: "qrc:nonexistingfile.haptic" +} diff --git a/tests/auto/qdeclarativefeedback/data/hapticseffect.qml b/tests/auto/qdeclarativefeedback/data/hapticseffect.qml new file mode 100644 index 0000000..edb025a --- /dev/null +++ b/tests/auto/qdeclarativefeedback/data/hapticseffect.qml @@ -0,0 +1,12 @@ +import QtMobility.feedback 1.1 + +HapticsEffect { + id: rumbleEffect + attackIntensity: 0.0 + attackTime: 250 + intensity: 1.0 + duration: 100 + fadeTime: 250 + fadeIntensity: 0.0 + actuator: Actuator {} +}
\ No newline at end of file diff --git a/tests/auto/qdeclarativefeedback/data/themeeffect.qml b/tests/auto/qdeclarativefeedback/data/themeeffect.qml new file mode 100644 index 0000000..a426fe5 --- /dev/null +++ b/tests/auto/qdeclarativefeedback/data/themeeffect.qml @@ -0,0 +1,5 @@ +import QtMobility.feedback 1.1 + +ThemeEffect { + effect: ThemeEffect.BasicButton; +} diff --git a/tests/auto/qdeclarativefeedback/data/themeeffect2.qml b/tests/auto/qdeclarativefeedback/data/themeeffect2.qml new file mode 100644 index 0000000..235180e --- /dev/null +++ b/tests/auto/qdeclarativefeedback/data/themeeffect2.qml @@ -0,0 +1,4 @@ +import QtMobility.feedback 1.1 + +// Test string enum +ThemeEffect {effect: "RotateStep"} diff --git a/tests/auto/qdeclarativefeedback/data/themeeffect3.qml b/tests/auto/qdeclarativefeedback/data/themeeffect3.qml new file mode 100644 index 0000000..72c7407 --- /dev/null +++ b/tests/auto/qdeclarativefeedback/data/themeeffect3.qml @@ -0,0 +1,7 @@ +import Qt 4.7; +import QtMobility.feedback 1.1; + +// Test default method +Item { + Component.onCompleted: ThemeEffect {effect: "ItemMoveOver"} +} diff --git a/tests/auto/qdeclarativefeedback/qdeclarativefeedback.pro b/tests/auto/qdeclarativefeedback/qdeclarativefeedback.pro new file mode 100644 index 0000000..b75c2c8 --- /dev/null +++ b/tests/auto/qdeclarativefeedback/qdeclarativefeedback.pro @@ -0,0 +1,25 @@ +include(../auto.pri) + +QMAKE_LIBS += -Wl,-rpath,$${QT.feedback.libs} + +QT += declarative feedback network script + +SOURCES += tst_qdeclarativefeedback.cpp + +symbian: { + importFiles.sources = data + importFiles.path = . + DEPLOYMENT += importFiles +} else { + DEFINES += SRCDIR=\\\"$$PWD\\\" +} + +OTHER_FILES += \ + data/hapticseffect.qml \ + data/fileeffect.qml \ + data/actuator.qml \ + data/themeeffect.qml \ + data/themeeffect2.qml \ + data/themeeffect3.qml + +maemo*:CONFIG += insignificant_test diff --git a/tests/auto/qdeclarativefeedback/tst_qdeclarativefeedback.cpp b/tests/auto/qdeclarativefeedback/tst_qdeclarativefeedback.cpp new file mode 100644 index 0000000..e3ba4a9 --- /dev/null +++ b/tests/auto/qdeclarativefeedback/tst_qdeclarativefeedback.cpp @@ -0,0 +1,207 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 <qtest.h> +#include <QtDeclarative/qdeclarativecomponent.h> +#include <QtDeclarative/qdeclarativeengine.h> +#include <qfeedbackeffect.h> +#include <qfeedbackactuator.h> + +#ifdef Q_OS_SYMBIAN +// In Symbian OS test data is located in applications private dir +#define SRCDIR "." +#endif + +QTM_USE_NAMESPACE + +#ifndef QTRY_COMPARE +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) +#endif + + +Q_DECLARE_METATYPE(QFeedbackEffect::ThemeEffect); + +class tst_qdeclarativefeedback : public QObject + +{ + Q_OBJECT +public: + tst_qdeclarativefeedback(); + +private slots: + void hapticsEffect(); + void fileEffect(); + void actuator(); + void themeEffect(); + +private: + QDeclarativeEngine engine; +}; + +tst_qdeclarativefeedback::tst_qdeclarativefeedback() +{ +} + +void tst_qdeclarativefeedback::hapticsEffect() +{ + QDeclarativeComponent component(&engine); + component.loadUrl(QUrl::fromLocalFile(SRCDIR "/data/hapticseffect.qml")); + + QObject *hapticsEffect = component.create(); + QVERIFY(hapticsEffect != 0); + + QCOMPARE(hapticsEffect->property("attackIntensity").toReal(), 0.0); + QCOMPARE(hapticsEffect->property("attackTime").toInt(), 250); + QCOMPARE(hapticsEffect->property("intensity").toReal(), 1.0); + QCOMPARE(hapticsEffect->property("duration").toInt(), 100); + QCOMPARE(hapticsEffect->property("fadeTime").toInt(), 250); + QCOMPARE(hapticsEffect->property("fadeIntensity").toReal(), 0.0); + QVERIFY(!hapticsEffect->property("actuator").isNull()); + QCOMPARE(hapticsEffect->property("state").toInt(), (int)(QFeedbackEffect::Stopped)); + + if (!hapticsEffect->property("availableActuators").toList().isEmpty()) { + QCOMPARE(hapticsEffect->property("running").toBool(), false); + QCOMPARE(hapticsEffect->property("paused").toBool(), false); + hapticsEffect->setProperty("running", true); + QCOMPARE(hapticsEffect->property("running").toBool(), true); + QCOMPARE(hapticsEffect->property("paused").toBool(), false); + hapticsEffect->setProperty("paused", true); + + // XXX make sure we just test dummy backend + QCOMPARE(hapticsEffect->property("running").toBool(), false); + QCOMPARE(hapticsEffect->property("paused").toBool(), true); + } + delete hapticsEffect; +} + +void tst_qdeclarativefeedback::fileEffect() +{ + QDeclarativeComponent component(&engine); + component.loadUrl(QUrl::fromLocalFile(SRCDIR "/data/fileeffect.qml")); + + QObject *fileEffect = component.create(); + QVERIFY(fileEffect != 0); + + QCOMPARE(fileEffect->property("source").toUrl(), QUrl("qrc:nonexistingfile.haptic")); + QCOMPARE(fileEffect->property("loaded").toBool(), false); + QTRY_COMPARE(fileEffect->property("state").toInt(), (int)(QFeedbackEffect::Stopped)); + + QCOMPARE(fileEffect->property("running").toBool(), false); + QCOMPARE(fileEffect->property("paused").toBool(), false); + fileEffect->setProperty("running", true); + fileEffect->setProperty("paused", true); + + // dummy backend + QTRY_COMPARE(fileEffect->property("running").toBool(), false); + QTRY_COMPARE(fileEffect->property("paused").toBool(), false); + + delete fileEffect; +} + +void tst_qdeclarativefeedback::actuator() +{ + QDeclarativeComponent component(&engine); + component.loadUrl(QUrl::fromLocalFile(SRCDIR "/data/actuator.qml")); + + QObject *actuator = component.create(); + QVERIFY(actuator != 0); + QCOMPARE(actuator->property("enabled").toBool(), false); + + delete actuator; +} + +void tst_qdeclarativefeedback::themeEffect() +{ + QDeclarativeComponent component(&engine); + component.loadUrl(QUrl::fromLocalFile(SRCDIR "/data/themeeffect.qml")); + + // We don't export this class, but we're just poking at properties anyway + QObject *dte = component.create(); + QCOMPARE(component.errorString(), QString()); + QVERIFY(dte != 0); + + // Test the effect property gets assigned + QMetaProperty p = dte->metaObject()->property(dte->metaObject()->indexOfProperty("effect")); + QCOMPARE(p.read(dte).value<int>(), (int)QFeedbackEffect::ThemeBasicButton); + + p = dte->metaObject()->property(dte->metaObject()->indexOfProperty("supported")); + QCOMPARE(p.read(dte).value<bool>(), QFeedbackEffect::supportsThemeEffect()); + + delete dte; + + component.loadUrl(QUrl::fromLocalFile(SRCDIR "/data/themeeffect2.qml")); + + dte = component.create(); + QCOMPARE(component.errorString(), QString()); + + QVERIFY(dte != 0); + // Effect property as a string + p = dte->metaObject()->property(dte->metaObject()->indexOfProperty("effect")); + QCOMPARE(p.read(dte).value<int>(), (int)QFeedbackEffect::ThemeRotateStep); + + delete dte; + + // Now test the default method + component.loadUrl(QUrl::fromLocalFile(SRCDIR "/data/themeeffect3.qml")); + + dte = component.create(); + QCOMPARE(component.errorString(), QString()); + QVERIFY(dte != 0); + + // Well, we can only verify that through a dummy plugin (TODO). verified through qdebug atm :) + + delete dte; +} + +QTEST_MAIN(tst_qdeclarativefeedback) + +#include "tst_qdeclarativefeedback.moc" diff --git a/tests/auto/qfeedbackactuator/qfeedbackactuator.pro b/tests/auto/qfeedbackactuator/qfeedbackactuator.pro new file mode 100644 index 0000000..0595f87 --- /dev/null +++ b/tests/auto/qfeedbackactuator/qfeedbackactuator.pro @@ -0,0 +1,9 @@ +include(../auto.pri) + +QMAKE_LIBS += -Wl,-rpath,$${QT.feedback.libs} + +QT += feedback + +SOURCES += tst_qfeedbackactuator.cpp + +symbian|linux-g++-maemo:DEFINES += HAVE_ACTUATORS diff --git a/tests/auto/qfeedbackactuator/tst_qfeedbackactuator.cpp b/tests/auto/qfeedbackactuator/tst_qfeedbackactuator.cpp new file mode 100644 index 0000000..66f4a36 --- /dev/null +++ b/tests/auto/qfeedbackactuator/tst_qfeedbackactuator.cpp @@ -0,0 +1,152 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/feedback + +#include <QtTest/QtTest> + +#include <qfeedbackactuator.h> + +QT_USE_NAMESPACE + +class tst_QFeedbackActuator : public QObject +{ + Q_OBJECT +public: + tst_QFeedbackActuator(); + ~tst_QFeedbackActuator(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void enumeration(); + void setEnabled(); +}; + +tst_QFeedbackActuator::tst_QFeedbackActuator() +{ +} + +tst_QFeedbackActuator::~tst_QFeedbackActuator() +{ +} + +void tst_QFeedbackActuator::initTestCase() +{ +} + +void tst_QFeedbackActuator::cleanupTestCase() +{ +} + +void tst_QFeedbackActuator::init() +{ + //the list returned should always be the same with the same order + QCOMPARE(QFeedbackActuator::actuators(), QFeedbackActuator::actuators()); +} + +void tst_QFeedbackActuator::cleanup() +{ +} + + +#if defined(HAVE_ACTUATORS) && !defined(Q_OS_SYMBIAN) +//we're on meego/maemo +#define CAPABILITY true //the capabilities are supported through Immersion +#else +#define CAPABILITY false +#endif + +void tst_QFeedbackActuator::enumeration() +{ + QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators(); +#ifdef HAVE_ACTUATORS + QVERIFY(!actuators.isEmpty()); +#endif + foreach(QFeedbackActuator* actuator, actuators) { + if (actuator->name() == QString("test plugin") || actuator->name() == QString("5555")) + continue; + + QVERIFY(actuator->isValid()); + QVERIFY(actuator->id() >= 0); + QCOMPARE(actuator->isCapabilitySupported(QFeedbackActuator::Envelope), CAPABILITY); + QCOMPARE(actuator->isCapabilitySupported(QFeedbackActuator::Period), CAPABILITY); + QVERIFY(!actuator->name().isEmpty()); + } + + // Try comparisons + if (actuators.count() > 1) { + QFeedbackActuator* a1 = actuators.at(0); + QFeedbackActuator* a2 = actuators.at(1); + QFeedbackActuator* a1b = actuators.at(0); + QFeedbackActuator* a2b = actuators.at(1); + QVERIFY(a1->id() != a2->id()); +// QVERIFY(*a1 != *a2); // doesn't work, no operator != !! + QVERIFY(!(*a1 == *a2)); + + QVERIFY(*a1 == *a1b); + QVERIFY(*a2 == *a2b); + } +} + +void tst_QFeedbackActuator::setEnabled() +{ + foreach(QFeedbackActuator* actuator, QFeedbackActuator::actuators()) { + if (actuator->name() == QString("test plugin") || actuator->name() == QString("5555")) + continue; + //this test might not always be true because you ight not be allowed to change the enabled property + actuator->setEnabled(false); + QVERIFY(!actuator->isEnabled()); + actuator->setEnabled(true); + QVERIFY(actuator->isEnabled()); + } +} + + + + +QTEST_MAIN(tst_QFeedbackActuator) + +#include "tst_qfeedbackactuator.moc" diff --git a/tests/auto/qfeedbackhapticseffect/qfeedbackhapticseffect.pro b/tests/auto/qfeedbackhapticseffect/qfeedbackhapticseffect.pro new file mode 100644 index 0000000..dbead9d --- /dev/null +++ b/tests/auto/qfeedbackhapticseffect/qfeedbackhapticseffect.pro @@ -0,0 +1,7 @@ +include(../auto.pri) + +QMAKE_LIBS += -Wl,-rpath,$${QT.feedback.libs} + +QT += feedback + +SOURCES += tst_qfeedbackhapticseffect.cpp diff --git a/tests/auto/qfeedbackhapticseffect/tst_qfeedbackhapticseffect.cpp b/tests/auto/qfeedbackhapticseffect/tst_qfeedbackhapticseffect.cpp new file mode 100644 index 0000000..d5870a2 --- /dev/null +++ b/tests/auto/qfeedbackhapticseffect/tst_qfeedbackhapticseffect.cpp @@ -0,0 +1,338 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/feedback + +#include <QtTest/QtTest> + +#include <qfeedbackeffect.h> +#include <qfeedbackactuator.h> + +QT_USE_NAMESPACE + +#ifndef QTRY_COMPARE +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) +#endif + +#ifndef QTRY_VERIFY +#define QTRY_VERIFY(__expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QVERIFY(__expr); \ + } while(0) +#endif + + +#define QTRY_WAIT(code, __expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + do { code } while(0); \ + QTest::qWait(__step); \ + } \ + } while(0) + + +class tst_QFeedbackHapticsEffect : public QObject +{ + Q_OBJECT +public: + tst_QFeedbackHapticsEffect(); + ~tst_QFeedbackHapticsEffect(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void initialization(); + void envelope_data(); + void envelope(); + void startStop_data(); + void startStop(); + void themeSupport(); + +}; + +tst_QFeedbackHapticsEffect::tst_QFeedbackHapticsEffect() +{ +} + +tst_QFeedbackHapticsEffect::~tst_QFeedbackHapticsEffect() +{ +} + +void tst_QFeedbackHapticsEffect::initTestCase() +{ +} + +void tst_QFeedbackHapticsEffect::cleanupTestCase() +{ +} + +void tst_QFeedbackHapticsEffect::init() +{ +#ifdef Q_OS_SYMBIAN + //we need that head start for the eventloop to be responsive + QTest::qWait(1000); +#endif +} + +void tst_QFeedbackHapticsEffect::cleanup() +{ +} + + +void tst_QFeedbackHapticsEffect::initialization() +{ + QFeedbackHapticsEffect effect; + if (QFeedbackActuator::actuators().isEmpty()) { + QVERIFY(!effect.actuator()->isValid()); + } else { + QVERIFY(effect.actuator()->isValid()); + QCOMPARE(effect.actuator(), QFeedbackActuator::actuators().first()); + } + + // actuators from other plugins need to be verified. + //test default values + QCOMPARE(effect.duration(), 250); //250ms is the default length for effects + QCOMPARE(effect.intensity(), qreal(1)); + QCOMPARE(effect.attackTime(), 0); + QCOMPARE(effect.attackIntensity(), qreal(0)); + QCOMPARE(effect.fadeTime(), 0); + QCOMPARE(effect.fadeIntensity(), qreal(0)); + QCOMPARE(effect.period(), -1); + QCOMPARE(effect.state(), QFeedbackEffect::Stopped); + +} + +void tst_QFeedbackHapticsEffect::envelope_data() +{ + QTest::addColumn<int>("duration"); + QTest::addColumn<qreal>("intensity"); + QTest::addColumn<int>("attackTime"); + QTest::addColumn<qreal>("attackIntensity"); + QTest::addColumn<int>("fadeTime"); + QTest::addColumn<qreal>("fadeIntensity"); + QTest::addColumn<int>("period"); + + QTest::newRow("TEST1") << 300 << qreal(.2) << 1 << qreal(.2) << 2 << qreal(1) << -1; + QTest::newRow("TEST2") << 500 << qreal(1) << 100 << qreal(.5) << 0 << qreal(0) << -1; + QTest::newRow("TEST3") << 250 << qreal(.8) << 150 << qreal(1) << 150 << qreal(1) << -1; + QTest::newRow("TEST period") << 1000 << qreal(1) << 150 << qreal(1) << 150 << qreal(1) << 150; +} + +void tst_QFeedbackHapticsEffect::envelope() +{ + QFETCH(int, duration); + QFETCH(qreal, intensity); + QFETCH(int, attackTime); + QFETCH(qreal, attackIntensity); + QFETCH(int, fadeTime); + QFETCH(qreal, fadeIntensity); + QFETCH(int, period); + + QFeedbackHapticsEffect effect; + + // actuators from other plugins need to be verified. + effect.setDuration(duration); + QCOMPARE(effect.duration(), duration); + + effect.setIntensity(intensity); + QCOMPARE(effect.intensity(), intensity); + + effect.setAttackTime(attackTime); + QCOMPARE(effect.attackTime(), attackTime); + + effect.setAttackIntensity(attackIntensity); + QCOMPARE(effect.attackIntensity(), attackIntensity); + + effect.setFadeTime(fadeTime); + QCOMPARE(effect.fadeTime(), fadeTime); + + effect.setFadeIntensity(fadeIntensity); + QCOMPARE(effect.fadeIntensity(), fadeIntensity); + + effect.setPeriod(period); + QCOMPARE(effect.period(), period); + + //test all the values at once + QCOMPARE(effect.duration(), duration); + QCOMPARE(effect.intensity(), intensity); + QCOMPARE(effect.attackTime(), attackTime); + QCOMPARE(effect.attackIntensity(), attackIntensity); + QCOMPARE(effect.fadeTime(), fadeTime); + QCOMPARE(effect.fadeIntensity(), fadeIntensity); + QCOMPARE(effect.period(), period); +} + + +void tst_QFeedbackHapticsEffect::startStop_data() +{ + envelope_data(); +} + +void tst_QFeedbackHapticsEffect::startStop() +{ + qRegisterMetaType<QFeedbackEffect::ErrorType>("QFeedbackEffect::ErrorType"); + if (QFeedbackActuator::actuators().isEmpty()) + QSKIP("this test requires to have actuators", SkipAll); + + QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators(); + + QFETCH(int, duration); + QFETCH(qreal, intensity); + QFETCH(int, attackTime); + QFETCH(qreal, attackIntensity); + QFETCH(int, fadeTime); + QFETCH(qreal, fadeIntensity); + QFETCH(int, period); + + QFeedbackHapticsEffect effect; + QSignalSpy errorspy(&effect, SIGNAL(error(QFeedbackEffect::ErrorType))); + QSignalSpy stateSpy(&effect, SIGNAL(stateChanged())); + + effect.setDuration(duration); + effect.setIntensity(intensity); + effect.setAttackTime(attackTime); + effect.setAttackIntensity(attackIntensity); + effect.setFadeTime(fadeTime); + effect.setFadeIntensity(fadeIntensity); + effect.setPeriod(period); + + QCOMPARE(effect.state(), QFeedbackHapticsEffect::Stopped); + QCOMPARE(effect.actuator(), actuators.at(0)); + + // Double set a few properties (shouldn't call the backend) + effect.setAttackTime(attackTime); + QVERIFY(effect.attackTime() == attackTime); + + effect.setFadeTime(fadeTime); + QVERIFY(effect.fadeTime() == fadeTime); + + // Test setting to a non default actuator and then back again + if (actuators.count() > 1) { + effect.setActuator(actuators.at(1)); + QCOMPARE(effect.actuator(), actuators.at(1)); + + effect.setActuator(0); + QCOMPARE(effect.actuator(), actuators.at(0)); + + // noop + effect.setActuator(actuators.at(0)); + QCOMPARE(effect.actuator(), actuators.at(0)); + } + + // Now start + QVERIFY(stateSpy.isEmpty()); + effect.start(); + QVERIFY(errorspy.isEmpty()); + + // This seems a little risky + QTRY_COMPARE(effect.state(), QFeedbackHapticsEffect::Running); + QVERIFY(errorspy.isEmpty()); + QCOMPARE(stateSpy.count(), 1); // stopped to start + + effect.pause(); + QCOMPARE(effect.state(), QFeedbackHapticsEffect::Paused); + QCOMPARE(stateSpy.count(), 2); + + // Now try to change a few properties (should be refused because of !Stopped) + effect.setPeriod(period + 100); + QVERIFY(effect.period() == period); + + QFeedbackActuator* actuator = effect.actuator(); + effect.setActuator(0); + QVERIFY(effect.actuator() == actuator); + + effect.start(); + QCOMPARE(effect.state(), QFeedbackHapticsEffect::Running); + QCOMPARE(stateSpy.count(), 3); + + QTRY_COMPARE(effect.state(), QFeedbackHapticsEffect::Stopped); + QVERIFY(errorspy.isEmpty()); + QCOMPARE(stateSpy.count(), 4); +} + + +void tst_QFeedbackHapticsEffect::themeSupport() +{ + const bool supportsTheme = QFeedbackEffect::supportsThemeEffect(); + + if (!supportsTheme) + QSKIP("No theme support", SkipAll); + int numberOfSupportedThemeEffects = 0; + for (int i = 0; i < QFeedbackEffect::NumberOfThemeEffects; ++i) { + if (QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeEffect(i))) + numberOfSupportedThemeEffects++; + QTest::qWait(250); //let's make sure the device is ready again + } + + QVERIFY(numberOfSupportedThemeEffects > 0); +} + +QTEST_MAIN(tst_QFeedbackHapticsEffect) + +#include "tst_qfeedbackhapticseffect.moc" diff --git a/tests/auto/qfeedbackmmk/qfeedbackmmk.pro b/tests/auto/qfeedbackmmk/qfeedbackmmk.pro new file mode 100644 index 0000000..ea91e85 --- /dev/null +++ b/tests/auto/qfeedbackmmk/qfeedbackmmk.pro @@ -0,0 +1,19 @@ +include(../auto.pri) + +QMAKE_LIBS += -Wl,-rpath,$${QT.feedback.libs} + +QT += feedback + +SOURCES += tst_qfeedbackmmk.cpp + +wince*|symbian { + deploy.files = test.wav + DEPLOYMENT = deploy + DEFINES += QT_QFEEDBACKMMK_USEAPPLICATIONPATH +} else:maemo* { + DEFINES += QT_QFEEDBACKMMK_USEAPPLICATIONPATH +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} + +maemo*:CONFIG += insignificant_test diff --git a/tests/auto/qfeedbackmmk/test.wav b/tests/auto/qfeedbackmmk/test.wav Binary files differnew file mode 100644 index 0000000..e4088a9 --- /dev/null +++ b/tests/auto/qfeedbackmmk/test.wav diff --git a/tests/auto/qfeedbackmmk/tst_qfeedbackmmk.cpp b/tests/auto/qfeedbackmmk/tst_qfeedbackmmk.cpp new file mode 100644 index 0000000..96d24c4 --- /dev/null +++ b/tests/auto/qfeedbackmmk/tst_qfeedbackmmk.cpp @@ -0,0 +1,253 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/feedback + +#include <QtTest/QtTest> + +#include <qfeedbackeffect.h> +#include <qfeedbackactuator.h> +#include <QSignalSpy> + +using namespace QTM_NAMESPACE; + +#ifndef QTRY_COMPARE +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) +#endif + +#ifndef QTRY_VERIFY +#define QTRY_VERIFY(__expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QVERIFY(__expr); \ + } while(0) +#endif + + +#define QTRY_WAIT(code, __expr) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if (!(__expr)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ + do { code } while(0); \ + QTest::qWait(__step); \ + } \ + } while(0) + + +class tst_QFeedbackMMK : public QObject +{ + Q_OBJECT +public: + tst_QFeedbackMMK(); + ~tst_QFeedbackMMK(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void goodFile(); + void badFile(); + +private: + QUrl url; +}; + +tst_QFeedbackMMK::tst_QFeedbackMMK() +{ +} + +tst_QFeedbackMMK::~tst_QFeedbackMMK() +{ +} + +void tst_QFeedbackMMK::initTestCase() +{ + // Some of this comes from the qsoundeffect testcase . .. ... +#ifdef QT_QFEEDBACKMMK_USEAPPLICATIONPATH + url = QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QString("/test.wav")); +#else + url = QUrl::fromLocalFile(QString(SRCDIR "test.wav")); +#endif +} + +void tst_QFeedbackMMK::cleanupTestCase() +{ +} + +void tst_QFeedbackMMK::init() +{ +#ifdef Q_OS_SYMBIAN + //we need that head start for the eventloop to be responsive + QTest::qWait(1000); +#endif +} + +void tst_QFeedbackMMK::cleanup() +{ +} + +Q_DECLARE_METATYPE(QFeedbackEffect::ErrorType); + +void tst_QFeedbackMMK::goodFile() +{ + QFeedbackFileEffect fe; + qRegisterMetaType<QFeedbackEffect::ErrorType>(); + QSignalSpy errorSpy(&fe, SIGNAL(error(QFeedbackEffect::ErrorType))); + QSignalSpy stateSpy(&fe, SIGNAL(stateChanged())); + + QFileInfo fi(url.toLocalFile()); + qDebug() << "URL for test data:" << url << url.toLocalFile() << fi.exists(); + + fe.setSource(url); + + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Loading); + QCOMPARE(errorSpy.count(), 0); + QCOMPARE(stateSpy.count(), 1); // Stopped to Loading + + // Wait for it to be loaded + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Stopped); + QCOMPARE(errorSpy.count(), 0); + QCOMPARE(stateSpy.count(), 2); // Stopped to Loading to Stopped + + // Now play! + fe.start(); + + // Now wait for it to be playing + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Running); + QCOMPARE(errorSpy.count(), 0); + QCOMPARE(stateSpy.count(), 3); // Stopped to Loading to Stopped to Running + QVERIFY(fe.isLoaded()); + QVERIFY(fe.duration() == 0); // unsupported :/ + + // Try pausing - not supported + fe.pause(); // XXX this emits stateChanged even when it fails + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Running); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(stateSpy.count(), 4); // Stopped to Loading to Stopped to Running + + // It should run out, eventually + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Stopped); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(stateSpy.count(), 5); // Stopped to Loading to Stopped to Running to Stopped + + // Play it again.. + fe.start(); + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Running); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(stateSpy.count(), 6); // Stopped to Loading to Stopped to Running to Stopped to Running + + fe.stop(); + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Stopped); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(stateSpy.count(), 7); // Stopped to Loading to Stopped to Running to Stopped to Running to Stopped + + fe.unload(); + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Stopped); + QCOMPARE(stateSpy.count(), 7); // no change + QCOMPARE(fe.isLoaded(), false); + QCOMPARE(fe.duration(), 0); + + // now load again + fe.load(); + QTRY_COMPARE((int)fe.state(), (int)QFeedbackFileEffect::Loading); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(stateSpy.count(), 8); // Stopped to Loading + + // Now wait for it to be loaded and playing + QTRY_COMPARE((int)fe.state(), (int) QFeedbackFileEffect::Stopped); + QCOMPARE(errorSpy.count(), 1); + QCOMPARE(stateSpy.count(), 9); // Stopped to Loading to Stopped + QVERIFY(fe.isLoaded()); + + // destroy it while playing +} + +void tst_QFeedbackMMK::badFile() +{ + QFeedbackFileEffect fe; + qRegisterMetaType<QFeedbackEffect::ErrorType>(); + QSignalSpy errorSpy(&fe, SIGNAL(error(QFeedbackEffect::ErrorType))); + QSignalSpy stateSpy(&fe, SIGNAL(stateChanged())); + + fe.setSource(QUrl("file:///does/not/exist/ever.wav")); + + // Depending on event loops we might miss the Loading state. + QTRY_COMPARE(stateSpy.count(), 2); // Loading & Stopped + QTRY_COMPARE(fe.state(), QFeedbackEffect::Stopped); + + QCOMPARE(errorSpy.count(), 1); + QVERIFY(fe.isLoaded() == false); + + fe.start(); // this actually causes a load, so it goes into LOADING, then fails, should go to STOPPED + QTRY_COMPARE(stateSpy.count(), 4); // Loading & Stopped + QTRY_COMPARE(fe.state(), QFeedbackEffect::Stopped); + QCOMPARE(errorSpy.count(), 2); + QVERIFY(fe.isLoaded() == false); +} + +QTEST_MAIN(tst_QFeedbackMMK) + +#include "tst_qfeedbackmmk.moc" diff --git a/tests/auto/qfeedbacknoplugins/qfeedbacknoplugins.pro b/tests/auto/qfeedbacknoplugins/qfeedbacknoplugins.pro new file mode 100644 index 0000000..1b46ccf --- /dev/null +++ b/tests/auto/qfeedbacknoplugins/qfeedbacknoplugins.pro @@ -0,0 +1,7 @@ +include(../auto.pri) + +QMAKE_LIBS += -Wl,-rpath,$${QT.feedback.libs} + +QT += feedback + +SOURCES += tst_qfeedbacknoplugins.cpp diff --git a/tests/auto/qfeedbacknoplugins/tst_qfeedbacknoplugins.cpp b/tests/auto/qfeedbacknoplugins/tst_qfeedbacknoplugins.cpp new file mode 100644 index 0000000..2b0415c --- /dev/null +++ b/tests/auto/qfeedbacknoplugins/tst_qfeedbacknoplugins.cpp @@ -0,0 +1,184 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/feedback + +#include <QtTest/QtTest> + +#include <qfeedbackeffect.h> +#include <qfeedbackactuator.h> + +QT_USE_NAMESPACE + +#ifndef QTRY_COMPARE +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) +#endif + +class tst_QFeedbackNoPlugins : public QObject +{ + Q_OBJECT +public: + tst_QFeedbackNoPlugins(); + ~tst_QFeedbackNoPlugins(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void testHapticEffect(); + void testFileEffect(); + void testThemeEffect(); + void testActuators(); +}; + +tst_QFeedbackNoPlugins::tst_QFeedbackNoPlugins() +{ + // This turns off plugin loading in unit test builds + qApp->setProperty("QFEEDBACK_TEST_NO_PLUGINS", 1); +} + +tst_QFeedbackNoPlugins::~tst_QFeedbackNoPlugins() +{ +} + +void tst_QFeedbackNoPlugins::initTestCase() +{ +} + +void tst_QFeedbackNoPlugins::cleanupTestCase() +{ +} + +void tst_QFeedbackNoPlugins::init() +{ +} + +void tst_QFeedbackNoPlugins::cleanup() +{ +} + +void tst_QFeedbackNoPlugins::testThemeEffect() +{ + // No plugins + QVERIFY(!QFeedbackEffect::supportsThemeEffect()); + QVERIFY(!QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeBasic)); + QVERIFY(!QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeBasicButton)); +} + +void tst_QFeedbackNoPlugins::testFileEffect() +{ + QFeedbackFileEffect fileEffect; + QVERIFY(QFeedbackFileEffect::supportedMimeTypes().isEmpty()); + + QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped); + + fileEffect.setSource(QUrl("load")); // this should call load + QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped); // fail :D + QVERIFY(!fileEffect.isLoaded()); + fileEffect.setLoaded(true); + QVERIFY(!fileEffect.isLoaded()); + fileEffect.setLoaded(false); + QVERIFY(!fileEffect.isLoaded()); + fileEffect.start(); + QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped); // fail :D +} + +void tst_QFeedbackNoPlugins::testHapticEffect() +{ + QFeedbackHapticsEffect testEffect; + + // it will do nothing, so stick some values in and play it. + testEffect.setAttackIntensity(0.0); + testEffect.setAttackTime(250); + testEffect.setIntensity(1.0); + testEffect.setDuration(100); + testEffect.setFadeTime(250); + testEffect.setFadeIntensity(0.0); + testEffect.start(); + QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Stopped); + testEffect.pause(); + QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Stopped); + testEffect.start(); + QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Stopped); + testEffect.stop(); + QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Stopped); +} + + +void tst_QFeedbackNoPlugins::testActuators() +{ + QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators(); + + // No plugins == no actuators + QVERIFY(actuators.isEmpty()); + + // Create a default one, anyway + QFeedbackActuator a; + + QVERIFY(a.isValid() == false); + QVERIFY(a.name().isEmpty()); + + QCOMPARE(a.isCapabilitySupported(QFeedbackActuator::Envelope), false); + QCOMPARE(a.isCapabilitySupported(QFeedbackActuator::Period), false); + + a.setEnabled(false); + QVERIFY(!a.isEnabled()); + a.setEnabled(true); + QVERIFY(!a.isEnabled()); +} + +QTEST_MAIN(tst_QFeedbackNoPlugins) + +#include "tst_qfeedbacknoplugins.moc" diff --git a/tests/auto/qfeedbackplugin/qfeedbackplugin.pro b/tests/auto/qfeedbackplugin/qfeedbackplugin.pro new file mode 100644 index 0000000..57d304b --- /dev/null +++ b/tests/auto/qfeedbackplugin/qfeedbackplugin.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs +SUBDIRS += testplugin \ + unittest \ + testplugin2 \ + testplugin3 diff --git a/tests/auto/qfeedbackplugin/testplugin/qfeedbacktestplugin.cpp b/tests/auto/qfeedbackplugin/testplugin/qfeedbacktestplugin.cpp new file mode 100644 index 0000000..383d816 --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin/qfeedbacktestplugin.cpp @@ -0,0 +1,222 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 <qfeedbackactuator.h> +#include "qfeedbacktestplugin.h" +#include <QtCore/QtPlugin> +#include <QtCore/QDebug> +#include <QtCore/QStringList> +#include <QtCore/QCoreApplication> +#include <QtCore/QFile> +#include <QtCore/QVariant> +#include <QDebug> + +Q_EXPORT_PLUGIN2(feedback_testplugin, QFeedbackTestPlugin) + + QFeedbackTestPlugin::QFeedbackTestPlugin() : QObject(qApp), mHapticState(QFeedbackEffect::Stopped), mFileState(QFeedbackEffect::Stopped) +{ + actuators_ << createFeedbackActuator(this, 0) << createFeedbackActuator(this, 1); +} + +QFeedbackTestPlugin::~QFeedbackTestPlugin() +{ +} + +QFeedbackInterface::PluginPriority QFeedbackTestPlugin::pluginPriority() +{ + return PluginHighPriority; // to make sure we get used +} + +QList<QFeedbackActuator*> QFeedbackTestPlugin::actuators() +{ + return actuators_; +} + +void QFeedbackTestPlugin::setActuatorProperty(const QFeedbackActuator &actuator, ActuatorProperty prop, const QVariant &value) +{ + Q_UNUSED(actuator) + Q_UNUSED(prop) + Q_UNUSED(value) +} + +QVariant QFeedbackTestPlugin::actuatorProperty(const QFeedbackActuator &actuator, ActuatorProperty prop) +{ + Q_UNUSED(actuator) + + switch (prop) { + case Name: + if (actuator.id() == 0) + return QString(QLatin1String("test plugin")); + else + return QString(QLatin1String("5555")); + + case State: + return static_cast<int>(QFeedbackActuator::Unknown); + + case Enabled: + return false; + default: + break; + } + + return QVariant(); +} + +bool QFeedbackTestPlugin::isActuatorCapabilitySupported(const QFeedbackActuator &, QFeedbackActuator::Capability cap) +{ + switch (cap) { + case QFeedbackActuator::Envelope: + case QFeedbackActuator::Period: + return true; + default: + break; + } + + return false; +} + +QTimer* QFeedbackTestPlugin::ensureTimer(const QFeedbackHapticsEffect* effect) +{ + // Yes, this is slow + QTimer *t = mHapticEffects.key(effect); + if (!t) { + t = new QTimer(); + t->setSingleShot(true); + t->setInterval(effect->duration()); + connect(t, SIGNAL(timeout()), this, SLOT(timerExpired())); + mHapticEffects.insert(t, effect); + } + return t; +} + + +void QFeedbackTestPlugin::updateEffectProperty(const QFeedbackHapticsEffect *effect, EffectProperty ep) +{ + if (ep == QFeedbackHapticsInterface::Duration) { + QTimer* t = ensureTimer(effect); + t->setInterval(effect->duration()); + } +} + +void QFeedbackTestPlugin::setEffectState(const QFeedbackHapticsEffect *effect, QFeedbackEffect::State state) +{ + Q_UNUSED(effect) + if (mHapticState != state) { + mHapticState = state; + QTimer* t = ensureTimer(effect); + if (mHapticState == QFeedbackEffect::Running) { + t->start(); + } else if (mHapticState == QFeedbackEffect::Stopped) { + t->stop(); + } else if (mHapticState == QFeedbackEffect::Paused) { + // In theory should set the duration to the remainder... + t->stop(); + } + } +} + +QFeedbackEffect::State QFeedbackTestPlugin::effectState(const QFeedbackHapticsEffect *effect) +{ + Q_UNUSED(effect) + return mHapticState; +} + +void QFeedbackTestPlugin::timerExpired() +{ + mHapticState = QFeedbackEffect::Stopped; + // Emit the stateChanged signal + const QFeedbackHapticsEffect* effect = mHapticEffects.value(static_cast<QTimer*>(sender())); + if (effect) { + QMetaObject::invokeMethod(const_cast<QFeedbackHapticsEffect*>(effect), "stateChanged"); + } +} + + + +void QFeedbackTestPlugin::setLoaded(QFeedbackFileEffect *effect, bool load) +{ + if (effect->source() == QUrl("load")) { + // Succeed the load + if (load) { + mFileState = QFeedbackEffect::Loading; + reportLoadFinished(effect, true); // not strictly true + } else + mFileState = QFeedbackEffect::Stopped; + } else { + // Fail the load + if (load) + reportLoadFinished(effect, false); + } +} + +void QFeedbackTestPlugin::setEffectState(QFeedbackFileEffect *effect, QFeedbackEffect::State state) +{ + Q_UNUSED(effect) + if (effect->source() == QUrl("load")) // we only change state for good effects + mFileState = state; +} + +QFeedbackEffect::State QFeedbackTestPlugin::effectState(const QFeedbackFileEffect *effect) +{ + Q_UNUSED(effect) + return mFileState; +} + +int QFeedbackTestPlugin::effectDuration(const QFeedbackFileEffect *effect) +{ + Q_UNUSED(effect) + return 5678; +} + +QStringList QFeedbackTestPlugin::supportedMimeTypes() +{ + return QStringList() << "x-test/this is a test"; +} + +bool QFeedbackTestPlugin::play(QFeedbackEffect::ThemeEffect themeEffect) +{ + if (themeEffect == QFeedbackEffect::ThemeBasic) + return true; + else { + reportError(0, QFeedbackEffect::UnknownError); + return false; + } +} diff --git a/tests/auto/qfeedbackplugin/testplugin/qfeedbacktestplugin.h b/tests/auto/qfeedbackplugin/testplugin/qfeedbacktestplugin.h new file mode 100644 index 0000000..0c1c513 --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin/qfeedbacktestplugin.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QFEEDBACKTESTPLUGIN_H +#define QFEEDBACKTESTPLUGIN_H + + +#include <QtCore/QList> +#include <QtCore/QVector> +#include <QtCore/QHash> +#include <QtCore/QMap> +#include <QtCore/QObject> +#include <QtCore/QMutex> +#include <QtCore/QTimer> + +#include <qfeedbackplugininterfaces.h> + +QT_BEGIN_HEADER +QT_USE_NAMESPACE + +class QFeedbackTestPlugin : public QObject, public QFeedbackHapticsInterface, public QFeedbackFileInterface, public QFeedbackThemeInterface +{ + Q_OBJECT + Q_INTERFACES(QFeedbackHapticsInterface) + Q_INTERFACES(QFeedbackFileInterface) + Q_INTERFACES(QFeedbackThemeInterface) +public: + QFeedbackTestPlugin(); + virtual ~QFeedbackTestPlugin(); + + virtual PluginPriority pluginPriority(); + + virtual QList<QFeedbackActuator*> actuators(); + + //for actuator handling + virtual void setActuatorProperty(const QFeedbackActuator &, ActuatorProperty, const QVariant &); + virtual QVariant actuatorProperty(const QFeedbackActuator &, ActuatorProperty); + virtual bool isActuatorCapabilitySupported(const QFeedbackActuator &, QFeedbackActuator::Capability); + + virtual void updateEffectProperty(const QFeedbackHapticsEffect *, EffectProperty); + virtual void setEffectState(const QFeedbackHapticsEffect *, QFeedbackEffect::State); + virtual QFeedbackEffect::State effectState(const QFeedbackHapticsEffect *); + + //for loading files + virtual void setLoaded(QFeedbackFileEffect*, bool); + virtual void setEffectState(QFeedbackFileEffect *, QFeedbackEffect::State); + virtual QFeedbackEffect::State effectState(const QFeedbackFileEffect *); + virtual int effectDuration(const QFeedbackFileEffect *); + virtual QStringList supportedMimeTypes(); + + // For themes + virtual bool play(QFeedbackEffect::ThemeEffect); + +private slots: + void timerExpired(); + +private: + QList<QFeedbackActuator*> actuators_; + + // Our hacky state + QFeedbackEffect::State mHapticState; + QFeedbackEffect::State mFileState; + QMap<QTimer*, const QFeedbackHapticsEffect*> mHapticEffects; + QTimer* ensureTimer(const QFeedbackHapticsEffect* effect); +}; + +QT_END_HEADER + +#endif diff --git a/tests/auto/qfeedbackplugin/testplugin/testplugin.pro b/tests/auto/qfeedbackplugin/testplugin/testplugin.pro new file mode 100644 index 0000000..06b85f9 --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin/testplugin.pro @@ -0,0 +1,30 @@ +load(qt_module) + +TARGET = qtfeedback_immersion +QT = core feedback + +load(qt_plugin) + +DESTDIR = $$QT.feedback.plugins/feedback + +INCLUDEPATH += $$QT.feedback.includes + +HEADERS += qfeedbacktestplugin.h +SOURCES += qfeedbacktestplugin.cpp + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + TARGET = $${TARGET}$${QT_LIBINFIX} + load(armcc_warnings) + + target.path = /sys/bin + INSTALLS += target + + symbianplugin.sources = $${TARGET}.dll + symbianplugin.path = $${QT_PLUGINS_BASE_DIR}/$${PLUGIN_TYPE} + DEPLOYMENT += symbianplugin +} + +target.path += $$[QT_INSTALL_PLUGINS]/feedback +INSTALLS += target diff --git a/tests/auto/qfeedbackplugin/testplugin2/qfeedbacktestplugin.cpp b/tests/auto/qfeedbackplugin/testplugin2/qfeedbacktestplugin.cpp new file mode 100644 index 0000000..425d4d9 --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin2/qfeedbacktestplugin.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 <qfeedbackactuator.h> +#include "qfeedbacktestplugin.h" +#include <QtCore/QtPlugin> +#include <QtCore/QDebug> +#include <QtCore/QStringList> +#include <QtCore/QCoreApplication> +#include <QtCore/QFile> +#include <QtCore/QVariant> +#include <QDebug> + +Q_EXPORT_PLUGIN2(feedback_atestplugin, QFeedbackTestPlugin) + +QFeedbackTestPlugin::QFeedbackTestPlugin() + : QObject(qApp) +{ +} + +QFeedbackTestPlugin::~QFeedbackTestPlugin() +{ +} diff --git a/tests/auto/qfeedbackplugin/testplugin2/qfeedbacktestplugin.h b/tests/auto/qfeedbackplugin/testplugin2/qfeedbacktestplugin.h new file mode 100644 index 0000000..6d24285 --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin2/qfeedbacktestplugin.h @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QFEEDBACKTESTPLUGIN_H +#define QFEEDBACKTESTPLUGIN_H + +#include <QtCore/QList> +#include <QtCore/QVector> +#include <QtCore/QHash> +#include <QtCore/QMap> +#include <QtCore/QObject> +#include <QtCore/QMutex> +#include <QtCore/QTimer> + +#include <qfeedbackplugininterfaces.h> + +QT_BEGIN_HEADER +QT_USE_NAMESPACE + +class QFeedbackTestPlugin : public QObject, public QFeedbackThemeInterface +{ + Q_OBJECT + Q_INTERFACES(QFeedbackThemeInterface) +public: + QFeedbackTestPlugin(); + virtual ~QFeedbackTestPlugin(); + + virtual PluginPriority pluginPriority() {return QFeedbackInterface::PluginNormalPriority;} + virtual bool play(QFeedbackEffect::ThemeEffect) {return false;} +}; + + +QT_END_HEADER + +#endif diff --git a/tests/auto/qfeedbackplugin/testplugin2/testplugin2.pro b/tests/auto/qfeedbackplugin/testplugin2/testplugin2.pro new file mode 100644 index 0000000..57f3004 --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin2/testplugin2.pro @@ -0,0 +1,32 @@ +load(qt_module) + +TARGET = qtfeedback_immersion +QT = core feedback + +load(qt_plugin) + +DESTDIR = $$QT.feedback.plugins/feedback + +INCLUDEPATH += $$QT.feedback.includes + +CONFIG += testplugin + +HEADERS += qfeedbacktestplugin.h +SOURCES += qfeedbacktestplugin.cpp + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + TARGET = $${TARGET}$${QT_LIBINFIX} + load(armcc_warnings) + + target.path = /sys/bin + INSTALLS += target + + symbianplugin.sources = $${TARGET}.dll + symbianplugin.path = $${QT_PLUGINS_BASE_DIR}/$${PLUGIN_TYPE} + DEPLOYMENT += symbianplugin +} + +target.path += $$[QT_INSTALL_PLUGINS]/feedback +INSTALLS += target diff --git a/tests/auto/qfeedbackplugin/testplugin3/qfeedbacktestplugin.cpp b/tests/auto/qfeedbackplugin/testplugin3/qfeedbacktestplugin.cpp new file mode 100644 index 0000000..df09004 --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin3/qfeedbacktestplugin.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 <qfeedbackactuator.h> +#include "qfeedbacktestplugin.h" +#include <QtCore/QtPlugin> +#include <QtCore/QDebug> +#include <QtCore/QStringList> +#include <QtCore/QCoreApplication> +#include <QtCore/QFile> +#include <QtCore/QVariant> +#include <QDebug> + +Q_EXPORT_PLUGIN2(feedback_testplugin3, QFeedbackTestPlugin) + +QFeedbackTestPlugin::QFeedbackTestPlugin() + : QObject(qApp) +{ +} + +QFeedbackTestPlugin::~QFeedbackTestPlugin() +{ +} diff --git a/tests/auto/qfeedbackplugin/testplugin3/qfeedbacktestplugin.h b/tests/auto/qfeedbackplugin/testplugin3/qfeedbacktestplugin.h new file mode 100644 index 0000000..476e02b --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin3/qfeedbacktestplugin.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $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 QFEEDBACKTESTPLUGIN_H +#define QFEEDBACKTESTPLUGIN_H + +#include <QtCore/QList> +#include <QtCore/QVector> +#include <QtCore/QHash> +#include <QtCore/QMap> +#include <QtCore/QObject> +#include <QtCore/QMutex> +#include <QtCore/QTimer> + +#include <qfeedbackplugininterfaces.h> + +QT_BEGIN_HEADER +QT_USE_NAMESPACE + +class QFeedbackTestPlugin : public QObject, public QFeedbackThemeInterface +{ + Q_OBJECT + Q_INTERFACES(QFeedbackThemeInterface) +public: + QFeedbackTestPlugin(); + virtual ~QFeedbackTestPlugin(); + + virtual PluginPriority pluginPriority() {return QFeedbackInterface::PluginLowPriority;} + virtual bool play(QFeedbackEffect::ThemeEffect) {return false;} +}; + +QT_END_HEADER + +#endif diff --git a/tests/auto/qfeedbackplugin/testplugin3/testplugin3.pro b/tests/auto/qfeedbackplugin/testplugin3/testplugin3.pro new file mode 100644 index 0000000..57f3004 --- /dev/null +++ b/tests/auto/qfeedbackplugin/testplugin3/testplugin3.pro @@ -0,0 +1,32 @@ +load(qt_module) + +TARGET = qtfeedback_immersion +QT = core feedback + +load(qt_plugin) + +DESTDIR = $$QT.feedback.plugins/feedback + +INCLUDEPATH += $$QT.feedback.includes + +CONFIG += testplugin + +HEADERS += qfeedbacktestplugin.h +SOURCES += qfeedbacktestplugin.cpp + +symbian: { + TARGET.EPOCALLOWDLLDATA=1 + TARGET.CAPABILITY = All -Tcb + TARGET = $${TARGET}$${QT_LIBINFIX} + load(armcc_warnings) + + target.path = /sys/bin + INSTALLS += target + + symbianplugin.sources = $${TARGET}.dll + symbianplugin.path = $${QT_PLUGINS_BASE_DIR}/$${PLUGIN_TYPE} + DEPLOYMENT += symbianplugin +} + +target.path += $$[QT_INSTALL_PLUGINS]/feedback +INSTALLS += target diff --git a/tests/auto/qfeedbackplugin/unittest/tst_qfeedbackplugin.cpp b/tests/auto/qfeedbackplugin/unittest/tst_qfeedbackplugin.cpp new file mode 100644 index 0000000..6bb651c --- /dev/null +++ b/tests/auto/qfeedbackplugin/unittest/tst_qfeedbackplugin.cpp @@ -0,0 +1,222 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite 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$ +** +****************************************************************************/ + +//TESTED_COMPONENT=src/feedback + +#include <QtTest/QtTest> + +#include <qfeedbackeffect.h> +#include <qfeedbackactuator.h> + +QT_USE_NAMESPACE + +#ifndef QTRY_COMPARE +#define QTRY_COMPARE(__expr, __expected) \ + do { \ + const int __step = 50; \ + const int __timeout = 5000; \ + if ((__expr) != (__expected)) { \ + QTest::qWait(0); \ + } \ + for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ + QTest::qWait(__step); \ + } \ + QCOMPARE(__expr, __expected); \ + } while(0) +#endif + +class tst_QFeedbackPlugin : public QObject +{ + Q_OBJECT +public: + tst_QFeedbackPlugin(); + ~tst_QFeedbackPlugin(); + +public slots: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + +private slots: + void testPlugin(); + void testFileEffect(); + void testThemeEffect(); +}; + +tst_QFeedbackPlugin::tst_QFeedbackPlugin() +{ +} + +tst_QFeedbackPlugin::~tst_QFeedbackPlugin() +{ +} + +void tst_QFeedbackPlugin::initTestCase() +{ +} + +void tst_QFeedbackPlugin::cleanupTestCase() +{ +} + +void tst_QFeedbackPlugin::init() +{ +} + +void tst_QFeedbackPlugin::cleanup() +{ +} + +void tst_QFeedbackPlugin::testThemeEffect() +{ + QVERIFY(QFeedbackEffect::supportsThemeEffect()); + QVERIFY(QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeBasic)); + QVERIFY(!QFeedbackEffect::playThemeEffect(QFeedbackEffect::ThemeBasicButton)); +} + +void tst_QFeedbackPlugin::testFileEffect() +{ + QFeedbackFileEffect fileEffect; + QVERIFY(QFeedbackFileEffect::supportedMimeTypes().contains("x-test/this is a test")); + + QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped); + + fileEffect.setSource(QUrl("load")); // this should call load + QVERIFY(fileEffect.state() == QFeedbackEffect::Loading); + + fileEffect.setSource(QUrl("ignored")); // not stopped, should fail + QVERIFY(fileEffect.source() == QUrl("load")); + + QVERIFY(fileEffect.isLoaded()); + fileEffect.setLoaded(true); // should do nothing + QVERIFY(fileEffect.isLoaded()); + QCOMPARE(fileEffect.duration(), 5678); // from the plugin + + fileEffect.unload(); // should fail, since we're not STOPPED (HMM!!) + QVERIFY(fileEffect.isLoaded()); + + fileEffect.stop(); + QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped); + // Now we should be able to change things again + + // Make sure setting the source to the same thing is a noop + fileEffect.setSource(fileEffect.source()); + QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped); + + // Now unload + QVERIFY(fileEffect.isLoaded()); + fileEffect.unload(); + QVERIFY(!fileEffect.isLoaded()); + QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped); + QCOMPARE(fileEffect.duration(), 0); // unloaded, shouldn't call? + + // Change the url + fileEffect.setSource(QUrl("failload")); + QVERIFY(!fileEffect.isLoaded()); + // Spinning the event loop is necessary for mmk to fail a load + QTRY_COMPARE(fileEffect.state(), QFeedbackEffect::Stopped); + QCOMPARE(fileEffect.duration(), 0); // unknown + + fileEffect.setSource(QUrl("load")); + QVERIFY(fileEffect.isLoaded()); + QVERIFY(fileEffect.state() == QFeedbackEffect::Loading); + fileEffect.start(); + QVERIFY(fileEffect.state() == QFeedbackEffect::Running); + fileEffect.start(); + QVERIFY(fileEffect.state() == QFeedbackEffect::Running); + fileEffect.stop(); + QVERIFY(fileEffect.state() == QFeedbackEffect::Stopped); + fileEffect.pause(); + QVERIFY(fileEffect.state() == QFeedbackEffect::Paused); // XXX this is a strange transition +} + +void tst_QFeedbackPlugin::testPlugin() +{ + QFeedbackHapticsEffect testEffect; + // first get the actuators. we want to use the test plugin actuator. + QFeedbackActuator* testActuator; + QList<QFeedbackActuator*> actuators = QFeedbackActuator::actuators(); + QCOMPARE(actuators.count(), 2); + + QCOMPARE(actuators.at(0)->name(), QString("test plugin")); + QCOMPARE(actuators.at(0)->id(), 0); + QCOMPARE(actuators.at(1)->name(), QString("5555")); + QCOMPARE(actuators.at(1)->id(), 1); + + // make sure we found the test actuator... + testActuator = actuators.at(0); + + QCOMPARE(testActuator->name(), QString("test plugin")); + QCOMPARE(testActuator->id(), 0); // test + QVERIFY(testActuator->isCapabilitySupported(QFeedbackActuator::Period)); + testActuator->setEnabled(true); + QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false. + testActuator->setEnabled(false); + QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false. + testActuator->setEnabled(true); + QVERIFY(!testActuator->isEnabled()); // the test plugin always returns enabled = false. + QCOMPARE(testActuator->state(), QFeedbackActuator::Unknown); // and it always returns state = unknown. + // XXX TODO: ensure that a "working" plugin returns real values.. + + // then, ensure that the test effect uses this actuator. + testEffect.setActuator(testActuator); + + // it will do nothing, so stick some values in and play it. + testEffect.setAttackIntensity(0.0); + testEffect.setAttackTime(250); + testEffect.setIntensity(1.0); + testEffect.setDuration(100); + testEffect.setFadeTime(250); + testEffect.setFadeIntensity(0.0); + testEffect.start(); + QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Running); + testEffect.pause(); + QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Paused); + testEffect.start(); + QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Running); + testEffect.stop(); + QVERIFY(testEffect.state() == QFeedbackHapticsEffect::Stopped); +} + +QTEST_MAIN(tst_QFeedbackPlugin) + +#include "tst_qfeedbackplugin.moc" diff --git a/tests/auto/qfeedbackplugin/unittest/unittest.pro b/tests/auto/qfeedbackplugin/unittest/unittest.pro new file mode 100644 index 0000000..fb5dc0f --- /dev/null +++ b/tests/auto/qfeedbackplugin/unittest/unittest.pro @@ -0,0 +1,9 @@ +include(../../auto.pri) + +QMAKE_LIBS += -Wl,-rpath,$${QT.feedback.libs} + +QT += feedback + +SOURCES += tst_qfeedbackplugin.cpp + +symbian|linux-g++-maemo:DEFINES += HAVE_ACTUATORS diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..157ef34 --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += auto |