Debian Codegraph @

tests/auto/qfeedbackmmk/tst_qfeedbackmmk.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtFeedback module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21 ** included in the packaging of this file. Please review the following
22 ** information to ensure the GNU General Public License requirements will
23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24 **
25 ** $QT_END_LICENSE$
26 **
27 ****************************************************************************/
28
29 //TESTED_COMPONENT=src/feedback
30
31 #include <QtTest/QtTest>
32
33 #include <qfeedbackeffect.h>
34 #include <qfeedbackactuator.h>
35 #include <QSignalSpy>
36 #include <QFeedbackFileEffect>
37
38 class tst_QFeedbackMMK : public QObject
39 {
40 Q_OBJECT
41 public:
42 tst_QFeedbackMMK();
43 ~tst_QFeedbackMMK();
44
45 public slots:
46 void initTestCase();
47 void cleanupTestCase();
48 void init();
49 void cleanup();
50
51 private slots:
52 void badFile();
53
54 private:
55 QUrl url;
56 };
57
58 tst_QFeedbackMMK::tst_QFeedbackMMK()
59 {
60 }
61
62 tst_QFeedbackMMK::~tst_QFeedbackMMK()
63 {
64 }
65
66 void tst_QFeedbackMMK::initTestCase()
67 {
68 // Only perform tests if audio device exists
69 // have to check specific formats supported as test plugin maybe installed
70 QStringList mimeTypes = QFeedbackFileEffect::supportedMimeTypes();
71 if (!(mimeTypes.contains("audio/x-wav") || mimeTypes.contains("audio/wav")
72 || mimeTypes.contains("audio/wave") || mimeTypes.contains("audio/x-pn-wav")))
73 QSKIP("No audio devices available");
74
75 // Some of this comes from the qsoundeffect testcase . .. ...
76 #ifdef QT_QFEEDBACKMMK_USEAPPLICATIONPATH
77 url = QUrl::fromLocalFile(QCoreApplication::applicationDirPath() + QString("/test.wav"));
78 #else
79 url = QUrl::fromLocalFile(QString(SRCDIR "test.wav"));
80 #endif
81 }
82
83 void tst_QFeedbackMMK::cleanupTestCase()
84 {
85 }
86
87 void tst_QFeedbackMMK::init()
88 {
89 }
90
91 void tst_QFeedbackMMK::cleanup()
92 {
93 }
94
95 Q_DECLARE_METATYPE(QFeedbackEffect::ErrorType);
96
97 void tst_QFeedbackMMK::badFile()
98 {
99 QFeedbackFileEffect fe;
100 qRegisterMetaType<QFeedbackEffect::ErrorType>();
101 QSignalSpy errorSpy(&fe, SIGNAL(error(QFeedbackEffect::ErrorType)));
102 QSignalSpy stateSpy(&fe, SIGNAL(stateChanged()));
103
104 fe.setSource(QUrl("file:///does/not/exist/ever.wav"));
105
106 // Depending on event loops we might miss the Loading state.
107 QTRY_VERIFY(stateSpy.count() > 0); // Loading & Stopped
108 QTRY_COMPARE(fe.state(), QFeedbackEffect::Stopped);
109
110 QVERIFY(errorSpy.count() > 0);
111 QVERIFY(fe.isLoaded() == false);
112 stateSpy.clear();
113 errorSpy.clear();
114
115 fe.start(); // this actually causes a load, so it goes into LOADING, then fails, should go to STOPPED
116 QTRY_VERIFY(stateSpy.count() > 0); // Loading & Stopped
117 QTRY_COMPARE(fe.state(), QFeedbackEffect::Stopped);
118 QVERIFY(errorSpy.count() > 0);
119 QVERIFY(fe.isLoaded() == false);
120 }
121
122 QTEST_MAIN(tst_QFeedbackMMK)
123
124 #include "tst_qfeedbackmmk.moc"