1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtFeedback module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
//TESTED_COMPONENT=src/feedback
#include <QtTest/QtTest>
#include <qfeedbackeffect.h>
#include <qfeedbackactuator.h>
QT_USE_NAMESPACE
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::Press));
QVERIFY(!QFeedbackEffect::playThemeEffect(QFeedbackEffect::Release));
}
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"
|