author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 16:40:13 +0300 | |
changeset 22 | 79de32ba3296 |
parent 19 | fcece45ef507 |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
/* This file is part of the KDE project |
|
42 |
Copyright (C) 2006-2007 Matthias Kretz <kretz@kde.org> |
|
43 |
||
44 |
This program is free software; you can redistribute it and/or |
|
45 |
modify it under the terms of the GNU General Public License as |
|
46 |
published by the Free Software Foundation; either version 2 of |
|
47 |
the License, or (at your option) version 3. |
|
48 |
||
49 |
This program is distributed in the hope that it will be useful, |
|
50 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
51 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
52 |
GNU General Public License for more details. |
|
53 |
||
54 |
You should have received a copy of the GNU General Public License |
|
55 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
56 |
||
57 |
*/ |
|
58 |
||
59 |
#include <QtTest/QtTest> |
|
60 |
#include <QtCore/QDate> |
|
61 |
#include <QtCore/QDebug> |
|
62 |
#include <QtCore/QObject> |
|
63 |
#include <QtCore/QUrl> |
|
64 |
||
65 |
#ifndef QT_NO_PHONON |
|
66 |
#include <phonon/path.h> |
|
67 |
#include <phonon/audiooutput.h> |
|
68 |
#include <phonon/mediaobject.h> |
|
69 |
#include <phonon/phononnamespace.h> |
|
70 |
#include <phonon/audiooutput.h> |
|
71 |
#include <phonon/seekslider.h> |
|
72 |
#include <phonon/mediaobject.h> |
|
73 |
#include <phonon/volumeslider.h> |
|
74 |
#include <phonon/videowidget.h> |
|
75 |
#include <phonon/backendcapabilities.h> |
|
76 |
||
77 |
#include "qtesthelper.h" |
|
78 |
#include <cstdlib> |
|
79 |
#endif |
|
80 |
||
81 |
#ifndef Q_WS_WIN |
|
82 |
#include <unistd.h> |
|
83 |
#endif |
|
84 |
||
85 |
#ifdef Q_OS_WINCE |
|
86 |
#define MEDIA_FILE "/sax.wav" |
|
87 |
#define MEDIA_FILEPATH ":/media/sax.wav" |
|
88 |
const qint64 SEEK_BACKWARDS = 2000; |
|
89 |
const qint64 ALLOWED_TIME_FOR_SEEKING = 1500; // 1.5s |
|
90 |
const qint64 SEEKING_TOLERANCE = 250; |
|
91 |
#else |
|
92 |
#if defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_SYMBIAN) |
|
93 |
#define MEDIA_FILE "/sax.mp3" |
|
94 |
#define MEDIA_FILEPATH ":/media/sax.mp3" |
|
95 |
#else |
|
96 |
#define MEDIA_FILE "/sax.ogg" |
|
97 |
#define MEDIA_FILEPATH ":/media/sax.ogg" |
|
98 |
#endif |
|
99 |
const qint64 SEEK_BACKWARDS = 4000; |
|
100 |
const qint64 ALLOWED_TIME_FOR_SEEKING = 1000; // 1s |
|
101 |
const qint64 SEEKING_TOLERANCE = 0; |
|
102 |
#endif //Q_OS_WINCE |
|
103 |
||
104 |
class tst_MediaObject : public QObject |
|
105 |
{ |
|
106 |
Q_OBJECT |
|
107 |
public: |
|
108 |
tst_MediaObject() |
|
109 |
: m_success(false) |
|
110 |
{ |
|
111 |
qputenv("PHONON_GST_AUDIOSINK", "fake"); |
|
112 |
} |
|
113 |
||
114 |
#ifndef QT_NO_PHONON |
|
115 |
||
116 |
Q_SIGNALS: |
|
117 |
void continueTestPlayOnFinish(); |
|
118 |
||
119 |
protected Q_SLOTS: |
|
120 |
void enqueueMedia(); |
|
121 |
void setMediaAndPlay(); |
|
122 |
void stateChanged(Phonon::State, Phonon::State); |
|
123 |
private Q_SLOTS: |
|
124 |
void init(); |
|
125 |
void cleanup(); |
|
126 |
||
127 |
void testPlayFromResource(); |
|
128 |
void testPlayIllegalFile(); |
|
129 |
void initTestCase(); |
|
130 |
void checkForDefaults(); |
|
131 |
||
132 |
// state change tests |
|
133 |
void stopToStop(); |
|
134 |
void stopToPause(); |
|
135 |
void stopToPlay(); |
|
136 |
void playToPlay(); |
|
137 |
void playToPause(); |
|
138 |
void playToStop(); |
|
139 |
void pauseToPause(); |
|
140 |
void pauseToPlay(); |
|
141 |
void pauseToStop(); |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
142 |
void playSDP(); |
0 | 143 |
|
144 |
void testPrefinishMark(); |
|
145 |
void testSeek(); |
|
146 |
void testTickSignal(); |
|
147 |
void testJustInTimeQueuing(); |
|
148 |
void testPlayOnFinish(); |
|
149 |
void testPlayBeforeFinish(); |
|
150 |
void testPauseOnFinish(); |
|
151 |
void testReconnectBetweenTwoMediaObjects(); |
|
152 |
void volumeSliderMuteVisibility(); |
|
153 |
void cleanupTestCase(); |
|
154 |
private: |
|
155 |
void _startPlayback(Phonon::State currentState = Phonon::StoppedState); |
|
156 |
void _stopPlayback(Phonon::State currentState); |
|
157 |
void _pausePlayback(); |
|
158 |
void _testOneSeek(qint64 seekTo); |
|
159 |
||
160 |
QUrl m_url; |
|
161 |
Phonon::MediaObject *m_media; |
|
162 |
QSignalSpy *m_stateChangedSignalSpy; |
|
163 |
QString m_tmpFileName; |
|
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
164 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
165 |
static void copyMediaFile(const QString &original, |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
166 |
const QString &name, |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
167 |
QString &resultFilePath, |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
168 |
QUrl *const asURL = 0); |
0 | 169 |
#endif //QT_NO_PHONON |
170 |
bool m_success; |
|
171 |
}; |
|
172 |
||
173 |
#ifndef QT_NO_PHONON |
|
174 |
||
175 |
#define startPlayback() _startPlayback(); if (!m_success) return; m_success = false; |
|
176 |
#define startPlayback2(currentState) _startPlayback(currentState); if (!m_success) return; m_success = false; |
|
177 |
#define stopPlayback(currentState) _stopPlayback(currentState); if (!m_success) return; m_success = false; |
|
178 |
#define pausePlayback() _pausePlayback(); if (!m_success) return; m_success = false; |
|
179 |
#define testOneSeek(seekTo) _testOneSeek(seekTo); if (!m_success) return; m_success = false; |
|
180 |
||
181 |
const qint64 ALLOWED_SEEK_INACCURACY = 300; // 0.3s |
|
182 |
const qint64 ALLOWED_TICK_INACCURACY = 350; // allow +/- 350 ms inaccuracy |
|
183 |
||
184 |
using namespace Phonon; |
|
185 |
||
186 |
static qint64 castQVariantToInt64(const QVariant &variant) |
|
187 |
{ |
|
188 |
return *reinterpret_cast<const qint64 *>(variant.constData()); |
|
189 |
} |
|
190 |
||
191 |
static qint32 castQVariantToInt32(const QVariant &variant) |
|
192 |
{ |
|
193 |
return *reinterpret_cast<const qint32 *>(variant.constData()); |
|
194 |
} |
|
195 |
||
196 |
void tst_MediaObject::stateChanged(Phonon::State newstate, Phonon::State oldstate) |
|
197 |
{ |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
198 |
if (newstate == Phonon::ErrorState) |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
199 |
QWARN(QByteArray(QByteArray(QTest::toString(oldstate)) + " to " + QByteArray(QTest::toString(newstate)))); |
0 | 200 |
} |
201 |
||
202 |
void tst_MediaObject::testPlayFromResource() |
|
203 |
{ |
|
204 |
#ifdef Q_OS_SYMBIAN |
|
205 |
QSKIP("Not implemented yet.", SkipAll); |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
206 |
#else |
0 | 207 |
QFile file(MEDIA_FILEPATH); |
208 |
MediaObject media; |
|
209 |
media.setCurrentSource(&file); |
|
210 |
QVERIFY(media.state() != Phonon::ErrorState); |
|
211 |
if (media.state() != Phonon::StoppedState) |
|
212 |
QTest::waitForSignal(&media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
|
213 |
QCOMPARE(media.state(), Phonon::StoppedState); |
|
214 |
media.play(); |
|
215 |
if (media.state() != Phonon::PlayingState) |
|
216 |
QTest::waitForSignal(&media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
|
217 |
QCOMPARE(media.state(), Phonon::PlayingState); |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
218 |
#endif |
0 | 219 |
} |
220 |
||
221 |
void tst_MediaObject::testPlayIllegalFile() |
|
222 |
{ |
|
223 |
QString filename = QDir::tempPath() + QString("/test.wav"); |
|
224 |
QFile::remove(filename); |
|
225 |
QFile file(filename); |
|
226 |
file.open(QIODevice::WriteOnly); |
|
227 |
for (int i=0;i<0xffff;i++) { |
|
228 |
int r = qrand(); |
|
229 |
file.write((const char*)&r, 2); |
|
230 |
} |
|
231 |
file.close(); |
|
232 |
MediaObject media; |
|
233 |
media.setCurrentSource(filename); |
|
234 |
QTest::waitForSignal(&media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
|
235 |
QCOMPARE(media.state(), Phonon::ErrorState); |
|
236 |
media.play(); |
|
237 |
QCOMPARE(media.state(), Phonon::ErrorState); |
|
238 |
QFile::remove(filename); |
|
239 |
} |
|
240 |
||
241 |
void tst_MediaObject::init() |
|
242 |
{ |
|
243 |
QCOMPARE(m_media->outputPaths().size(), 1); |
|
244 |
if (m_media->state() == Phonon::ErrorState) { |
|
245 |
m_media->setCurrentSource(m_url); |
|
246 |
if (m_media->state() == Phonon::ErrorState) { |
|
247 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
|
248 |
} |
|
249 |
if (m_media->state() == Phonon::LoadingState) { |
|
250 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
|
251 |
} |
|
252 |
m_stateChangedSignalSpy->clear(); |
|
253 |
} |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
254 |
|
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
255 |
// Ensure that m_media is in StoppedState |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
256 |
if (m_media->state() != Phonon::StoppedState) { |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
257 |
m_media->stop(); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
258 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
259 |
QCOMPARE(m_media->state(), Phonon::StoppedState); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
260 |
} |
0 | 261 |
} |
262 |
||
263 |
void tst_MediaObject::cleanup() |
|
264 |
{ |
|
265 |
switch (m_media->state()) { |
|
266 |
case Phonon::PlayingState: |
|
267 |
case Phonon::BufferingState: |
|
268 |
case Phonon::PausedState: |
|
269 |
stopPlayback(m_media->state()); |
|
270 |
break; |
|
271 |
default: |
|
272 |
break; |
|
273 |
} |
|
274 |
m_stateChangedSignalSpy->clear(); |
|
275 |
} |
|
276 |
||
277 |
void tst_MediaObject::_startPlayback(Phonon::State currentState) |
|
278 |
{ |
|
279 |
m_stateChangedSignalSpy->clear(); |
|
280 |
Phonon::State s = m_media->state(); |
|
281 |
QCOMPARE(s, currentState); |
|
282 |
m_media->play(); |
|
283 |
while (s != Phonon::PlayingState) { |
|
284 |
if (m_stateChangedSignalSpy->isEmpty()) { |
|
285 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 3000); |
|
286 |
QApplication::processEvents(); |
|
287 |
} |
|
288 |
while (!m_stateChangedSignalSpy->isEmpty()) { |
|
289 |
QList<QVariant> args = m_stateChangedSignalSpy->takeFirst(); |
|
290 |
Phonon::State laststate = qvariant_cast<Phonon::State>(args.at(1)); |
|
291 |
QCOMPARE(laststate, s); |
|
292 |
s = qvariant_cast<Phonon::State>(args.at(0)); |
|
293 |
QVERIFY(s == Phonon::BufferingState || s == Phonon::PlayingState); |
|
294 |
} |
|
295 |
} |
|
296 |
QCOMPARE(s, Phonon::PlayingState); |
|
297 |
QCOMPARE(m_media->state(), Phonon::PlayingState); |
|
298 |
m_success = true; |
|
299 |
} |
|
300 |
||
301 |
void tst_MediaObject::_stopPlayback(Phonon::State currentState) |
|
302 |
{ |
|
303 |
QVERIFY(currentState != Phonon::ErrorState); |
|
304 |
m_stateChangedSignalSpy->clear(); |
|
305 |
Phonon::State s = m_media->state(); |
|
306 |
QCOMPARE(s, currentState); |
|
307 |
m_media->stop(); |
|
308 |
while (s != Phonon::StoppedState) { |
|
309 |
if (m_stateChangedSignalSpy->isEmpty()) { |
|
310 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 4000)); |
|
311 |
} |
|
312 |
while (!m_stateChangedSignalSpy->isEmpty()) { |
|
313 |
QList<QVariant> args = m_stateChangedSignalSpy->takeFirst(); |
|
314 |
Phonon::State laststate = qvariant_cast<Phonon::State>(args.at(1)); |
|
315 |
QCOMPARE(laststate, s); |
|
316 |
s = qvariant_cast<Phonon::State>(args.at(0)); |
|
317 |
if (s == Phonon::StoppedState) { |
|
318 |
QVERIFY(m_stateChangedSignalSpy->isEmpty()); |
|
319 |
break; |
|
320 |
} |
|
321 |
QVERIFY(s == Phonon::BufferingState || s == Phonon::PlayingState); |
|
322 |
} |
|
323 |
} |
|
324 |
QCOMPARE(s, Phonon::StoppedState); |
|
325 |
QCOMPARE(m_media->state(), Phonon::StoppedState); |
|
326 |
m_success = true; |
|
327 |
} |
|
328 |
||
329 |
void tst_MediaObject::_pausePlayback() |
|
330 |
{ |
|
331 |
m_stateChangedSignalSpy->clear(); |
|
332 |
Phonon::State s = m_media->state(); |
|
333 |
m_media->pause(); |
|
334 |
while (s != Phonon::PausedState) { |
|
335 |
if (m_stateChangedSignalSpy->isEmpty()) { |
|
336 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
|
337 |
} |
|
338 |
while (!m_stateChangedSignalSpy->isEmpty()) { |
|
339 |
QList<QVariant> args = m_stateChangedSignalSpy->takeFirst(); |
|
340 |
Phonon::State laststate = qvariant_cast<Phonon::State>(args.at(1)); |
|
341 |
QCOMPARE(laststate, s); |
|
342 |
s = qvariant_cast<Phonon::State>(args.at(0)); |
|
343 |
if (s == Phonon::PausedState) { |
|
344 |
QVERIFY(m_stateChangedSignalSpy->isEmpty()); |
|
345 |
break; |
|
346 |
} |
|
347 |
QVERIFY(s == Phonon::BufferingState || s == Phonon::PlayingState); |
|
348 |
} |
|
349 |
} |
|
350 |
QCOMPARE(s, Phonon::PausedState); |
|
351 |
QCOMPARE(m_media->state(), Phonon::PausedState); |
|
352 |
m_success = true; |
|
353 |
} |
|
354 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
355 |
/*! |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
356 |
Copies the file \a name to the testing area. The resulting file name path is |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
357 |
returned in resultFilePath, and also set as a URL in \a asURL. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
358 |
*/ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
359 |
void tst_MediaObject::copyMediaFile(const QString &original, |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
360 |
const QString &name, |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
361 |
QString &resultFilePath, |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
362 |
QUrl *const asURL) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
363 |
{ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
364 |
resultFilePath = QDir::toNativeSeparators(QDir::tempPath() + name); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
365 |
if (asURL) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
366 |
*asURL = QUrl::fromLocalFile(resultFilePath); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
367 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
368 |
QFile::remove(resultFilePath); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
369 |
QVERIFY(QFile::copy(original, resultFilePath)); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
370 |
QFile::setPermissions(resultFilePath, QFile::permissions(resultFilePath) | QFile::WriteOther); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
371 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
372 |
|
0 | 373 |
void tst_MediaObject::initTestCase() |
374 |
{ |
|
375 |
QCoreApplication::setApplicationName("tst_MediaObject"); |
|
376 |
m_stateChangedSignalSpy = 0; |
|
377 |
m_media = 0; |
|
378 |
||
379 |
#ifdef Q_OS_WINCE |
|
380 |
QString pluginsPath = QLibraryInfo::location(QLibraryInfo::PluginsPath); |
|
381 |
#ifdef DEBUG |
|
382 |
QVERIFY(QFile::exists(pluginsPath + "/phonon_backend/phonon_waveoutd4.dll") || QFile::exists(pluginsPath + "/phonon_backend/phonon_phonon_ds9d4.dll")); |
|
383 |
#else |
|
384 |
QVERIFY(QFile::exists(pluginsPath + "/phonon_backend/phonon_waveout4.dll") || QFile::exists(pluginsPath + "/phonon_backend/phonon_phonon_ds94.dll")); |
|
385 |
#endif |
|
386 |
#endif |
|
387 |
||
388 |
||
389 |
m_url = qgetenv("PHONON_TESTURL"); |
|
390 |
m_media = new MediaObject(this); |
|
391 |
connect(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), SLOT(stateChanged(Phonon::State, Phonon::State))); |
|
392 |
m_stateChangedSignalSpy = new QSignalSpy(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
|
393 |
QVERIFY(m_stateChangedSignalSpy->isValid()); |
|
394 |
m_stateChangedSignalSpy->clear(); |
|
395 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
396 |
if (m_url.isEmpty()) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
397 |
copyMediaFile(MEDIA_FILEPATH, MEDIA_FILE, m_tmpFileName, &m_url); |
0 | 398 |
|
399 |
qDebug() << "Using url:" << m_url.toString(); |
|
400 |
||
401 |
// AudioOutput is needed else the backend might have no time source |
|
402 |
AudioOutput *audioOutput = new AudioOutput(Phonon::MusicCategory, this); |
|
403 |
//audioOutput->setVolume(0.0f); |
|
404 |
||
405 |
QSignalSpy totalTimeChangedSignalSpy(m_media, SIGNAL(totalTimeChanged(qint64))); |
|
406 |
QVERIFY(m_media->queue().isEmpty()); |
|
407 |
QCOMPARE(m_media->currentSource().type(), MediaSource::Empty); |
|
408 |
QCOMPARE(m_media->state(), Phonon::LoadingState); |
|
409 |
QCOMPARE(m_stateChangedSignalSpy->count(), 0); |
|
410 |
||
411 |
m_media->setCurrentSource(m_url); |
|
412 |
QCOMPARE(m_media->currentSource().type(), MediaSource::Url); |
|
413 |
QCOMPARE(m_media->currentSource().url(), m_url); |
|
414 |
||
415 |
int emits = m_stateChangedSignalSpy->count(); |
|
416 |
Phonon::State s = m_media->state(); |
|
417 |
if (s == Phonon::LoadingState) { |
|
418 |
// still in LoadingState, there should be no state change |
|
419 |
QCOMPARE(emits, 0); |
|
420 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 6000); |
|
421 |
emits = m_stateChangedSignalSpy->count(); |
|
422 |
s = m_media->state(); |
|
423 |
} |
|
424 |
if (s != Phonon::LoadingState) { |
|
425 |
// there should exactly be one state change |
|
426 |
QCOMPARE(emits, 1); |
|
427 |
QList<QVariant> args = m_stateChangedSignalSpy->takeFirst(); |
|
428 |
Phonon::State newstate = qvariant_cast<Phonon::State>(args.at(0)); |
|
429 |
Phonon::State oldstate = qvariant_cast<Phonon::State>(args.at(1)); |
|
430 |
||
431 |
QCOMPARE(Phonon::LoadingState, oldstate); |
|
432 |
QCOMPARE(s, newstate); |
|
433 |
if (Phonon::ErrorState == s) { |
|
434 |
#ifdef Q_WS_WIN |
|
435 |
if (m_media->errorString().contains(QLatin1String("no audio hardware is available"))) |
|
436 |
QSKIP("On Windows we need an audio devide to perform the MediaObject tests", SkipAll); |
|
437 |
else |
|
438 |
#endif |
|
439 |
QFAIL("Loading the URL put the MediaObject into the ErrorState. Check that PHONON_TESTURL is set to a valid URL."); |
|
440 |
} |
|
441 |
QCOMPARE(Phonon::StoppedState, s); |
|
442 |
QCOMPARE(m_stateChangedSignalSpy->count(), 0); |
|
443 |
||
444 |
// check for totalTimeChanged signal |
|
445 |
QVERIFY(totalTimeChangedSignalSpy.count() > 0); |
|
446 |
args = totalTimeChangedSignalSpy.takeLast(); |
|
447 |
QCOMPARE(m_media->totalTime(), castQVariantToInt64(args.at(0))); |
|
448 |
} else { |
|
449 |
QFAIL("Still in LoadingState after a stateChange signal was emitted. Cannot go on."); |
|
450 |
} |
|
451 |
||
452 |
Path path = createPath(m_media, audioOutput); |
|
453 |
QVERIFY(path.isValid()); |
|
454 |
||
455 |
||
456 |
QCOMPARE(m_media->outputPaths().size(), 1); |
|
457 |
QCOMPARE(audioOutput->inputPaths().size(), 1); |
|
458 |
||
459 |
} |
|
460 |
||
461 |
void tst_MediaObject::checkForDefaults() |
|
462 |
{ |
|
463 |
QCOMPARE(m_media->tickInterval(), qint32(0)); |
|
464 |
QCOMPARE(m_media->prefinishMark(), qint32(0)); |
|
465 |
} |
|
466 |
||
467 |
void tst_MediaObject::stopToStop() |
|
468 |
{ |
|
469 |
QCOMPARE(m_stateChangedSignalSpy->count(), 0); |
|
470 |
QCOMPARE(m_media->state(), Phonon::StoppedState); |
|
471 |
m_media->stop(); |
|
472 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 2000); |
|
473 |
QCOMPARE(m_stateChangedSignalSpy->count(), 0); |
|
474 |
QCOMPARE(m_media->state(), Phonon::StoppedState); |
|
475 |
} |
|
476 |
||
477 |
void tst_MediaObject::stopToPause() |
|
478 |
{ |
|
479 |
QCOMPARE(m_stateChangedSignalSpy->count(), 0); |
|
480 |
QCOMPARE(m_media->state(), Phonon::StoppedState); |
|
481 |
m_media->pause(); |
|
482 |
if (m_stateChangedSignalSpy->isEmpty()) { |
|
483 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 6000)); |
|
484 |
} |
|
485 |
QCOMPARE(m_stateChangedSignalSpy->count(), 1); |
|
486 |
QCOMPARE(m_media->state(), Phonon::PausedState); |
|
487 |
} |
|
488 |
||
489 |
void tst_MediaObject::stopToPlay() |
|
490 |
{ |
|
491 |
startPlayback(); |
|
492 |
QTest::waitForSignal(m_media, SIGNAL(finished()), 1000); |
|
493 |
stopPlayback(Phonon::PlayingState); |
|
494 |
} |
|
495 |
||
496 |
void tst_MediaObject::playToPlay() |
|
497 |
{ |
|
498 |
startPlayback(); |
|
499 |
||
500 |
m_media->play(); |
|
501 |
QCOMPARE(m_stateChangedSignalSpy->count(), 0); |
|
502 |
QCOMPARE(m_media->state(), Phonon::PlayingState); |
|
503 |
||
504 |
stopPlayback(Phonon::PlayingState); |
|
505 |
} |
|
506 |
||
507 |
void tst_MediaObject::playToPause() |
|
508 |
{ |
|
509 |
startPlayback(); |
|
510 |
QCOMPARE(m_media->state(), Phonon::PlayingState); |
|
511 |
pausePlayback(); |
|
512 |
stopPlayback(Phonon::PausedState); |
|
513 |
} |
|
514 |
||
515 |
void tst_MediaObject::playToStop() |
|
516 |
{ |
|
517 |
startPlayback(); |
|
518 |
stopPlayback(Phonon::PlayingState); |
|
519 |
} |
|
520 |
||
521 |
void tst_MediaObject::pauseToPause() |
|
522 |
{ |
|
523 |
startPlayback(); |
|
524 |
pausePlayback(); |
|
525 |
||
526 |
m_media->pause(); |
|
527 |
QCOMPARE(m_stateChangedSignalSpy->count(), 0); |
|
528 |
QCOMPARE(m_media->state(), Phonon::PausedState); |
|
529 |
||
530 |
stopPlayback(Phonon::PausedState); |
|
531 |
} |
|
532 |
||
533 |
void tst_MediaObject::pauseToPlay() |
|
534 |
{ |
|
535 |
startPlayback(); |
|
536 |
pausePlayback(); |
|
537 |
startPlayback2(Phonon::PausedState); |
|
538 |
stopPlayback(Phonon::PlayingState); |
|
539 |
} |
|
540 |
||
541 |
void tst_MediaObject::pauseToStop() |
|
542 |
{ |
|
543 |
startPlayback(); |
|
544 |
pausePlayback(); |
|
545 |
stopPlayback(Phonon::PausedState); |
|
546 |
} |
|
547 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
548 |
/*! |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
549 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
550 |
We attempt to play a SDP file. An SDP file essentially describes different |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
551 |
media streams and is hence a layer in front of the actual media(s). |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
552 |
Sometimes the backend handles the SDP file, in other cases not. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
553 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
554 |
Some Phonon backends doesn't support SDP at all, ifdef appropriately. Real |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
555 |
Player and Helix, the two backends for Symbian, are known to support SDP. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
556 |
*/ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
557 |
void tst_MediaObject::playSDP() |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
558 |
{ |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
559 |
#ifdef Q_OS_SYMBIAN |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
560 |
QString sdpFile; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
561 |
copyMediaFile(QLatin1String(":/media/test.sdp"), QLatin1String("test.sdp"), sdpFile); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
562 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
563 |
// Let's verify our test setup. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
564 |
QVERIFY(QFileInfo(sdpFile).isReadable()); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
565 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
566 |
// We need a window in order to setup the video. |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
567 |
QWidget widget; |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
568 |
widget.show(); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
569 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
570 |
const MediaSource oldSource(m_media->currentSource()); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
571 |
const MediaSource sdpSource(sdpFile); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
572 |
m_media->setCurrentSource(sdpSource); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
573 |
if (m_media->state() != Phonon::StoppedState) |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
574 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
575 |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
576 |
// MediaObject should have loaded the SDP, but be in error state due to absent media |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
577 |
const bool stateMatch = (m_media->state() == Phonon::ErrorState); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
578 |
const bool errorStringMatch = (m_media->errorString() == QString::fromLatin1("Loading clip failed: Unknown error (-39)")); |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
579 |
|
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
580 |
// Ensure that m_media is back in ground state prior to starting next test step |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
581 |
m_media->setCurrentSource(oldSource); |
22
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
582 |
if (m_media->state() != Phonon::StoppedState) |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
583 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
584 |
QCOMPARE(m_media->state(), Phonon::StoppedState); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
585 |
|
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
586 |
QVERIFY(stateMatch); |
79de32ba3296
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
587 |
QVERIFY(errorStringMatch); |
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
588 |
|
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
589 |
#else |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
590 |
QSKIP("Unsupported on this platform.", SkipAll); |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
591 |
#endif |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
592 |
} |
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
593 |
|
0 | 594 |
void tst_MediaObject::testPrefinishMark() |
595 |
{ |
|
596 |
const qint32 requestedPrefinishMarkTime = 2000; |
|
597 |
m_media->setPrefinishMark(requestedPrefinishMarkTime); |
|
598 |
QCOMPARE(m_media->prefinishMark(), requestedPrefinishMarkTime); |
|
599 |
QSignalSpy prefinishMarkReachedSpy(m_media, SIGNAL(prefinishMarkReached(qint32))); |
|
600 |
QSignalSpy finishSpy(m_media, SIGNAL(finished())); |
|
601 |
startPlayback(); |
|
602 |
if (m_media->isSeekable()) { |
|
603 |
m_media->seek(m_media->totalTime() - SEEK_BACKWARDS - requestedPrefinishMarkTime); // give it 4 seconds |
|
604 |
} |
|
605 |
int wait = 10000; |
|
606 |
int total = 0; |
|
607 |
while (prefinishMarkReachedSpy.count() == 0 && (m_media->state() == Phonon::PlayingState || |
|
608 |
m_media->state() == Phonon::BufferingState)) { |
|
609 |
wait = qMax(1000, wait / 2); |
|
610 |
QTest::waitForSignal(m_media, SIGNAL(prefinishMarkReached(qint32)), wait); |
|
611 |
total += wait; |
|
612 |
if (total >= 60*1000) // we wait 1 minute |
|
613 |
QFAIL("Timeout failure waiting for signal"); |
|
614 |
} |
|
615 |
// at this point the media should be about to finish playing |
|
616 |
qint64 r = m_media->remainingTime(); |
|
617 |
Phonon::State state = m_media->state(); |
|
618 |
QCOMPARE(prefinishMarkReachedSpy.count(), 1); |
|
619 |
const qint32 prefinishMark = castQVariantToInt32(prefinishMarkReachedSpy.first().at(0)); |
|
620 |
QVERIFY(prefinishMark <= requestedPrefinishMarkTime + 150); // allow it to be up to 150ms too early |
|
621 |
if (state == Phonon::PlayingState || state == Phonon::BufferingState) { |
|
622 |
if (r > prefinishMark) { |
|
623 |
qDebug() << "remainingTime =" << r; |
|
624 |
QFAIL("remainingTime needs to be less than or equal to prefinishMark"); |
|
625 |
} |
|
626 |
QVERIFY(r <= prefinishMark); |
|
627 |
QTest::waitForSignal(m_media, SIGNAL(finished()), 10000); |
|
628 |
} else { |
|
629 |
QVERIFY(prefinishMark >= 0); |
|
630 |
} |
|
631 |
QCOMPARE(finishSpy.count(), 1); |
|
632 |
} |
|
633 |
||
634 |
void tst_MediaObject::enqueueMedia() |
|
635 |
{ |
|
636 |
m_media->enqueue(m_url); |
|
637 |
} |
|
638 |
||
639 |
Q_DECLARE_METATYPE(Phonon::MediaSource) |
|
640 |
void tst_MediaObject::testJustInTimeQueuing() |
|
641 |
{ |
|
642 |
#ifdef Q_OS_WINCE |
|
643 |
QSKIP("crashes on Windows CE", SkipAll); |
|
644 |
#endif |
|
645 |
qRegisterMetaType<Phonon::MediaSource>("Phonon::MediaSource"); |
|
646 |
QSignalSpy currentSourceChanged(m_media, SIGNAL(currentSourceChanged(const Phonon::MediaSource &))); |
|
647 |
QSignalSpy finished(m_media, SIGNAL(finished())); |
|
648 |
connect(m_media, SIGNAL(aboutToFinish()), SLOT(enqueueMedia())); |
|
649 |
||
650 |
startPlayback(); |
|
651 |
if (m_media->isSeekable()) { |
|
652 |
m_media->seek(m_media->totalTime() - SEEK_BACKWARDS); |
|
653 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(aboutToFinish()), 6000)); |
|
654 |
} else { |
|
655 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(aboutToFinish()), 3000 + m_media->remainingTime())); |
|
656 |
} |
|
657 |
disconnect(m_media, SIGNAL(aboutToFinish()), this, SLOT(enqueueMedia())); |
|
658 |
if (currentSourceChanged.isEmpty()) { |
|
659 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(currentSourceChanged(const Phonon::MediaSource &)), 3000)); |
|
660 |
} |
|
661 |
QCOMPARE(currentSourceChanged.size(), 1); |
|
662 |
QCOMPARE(finished.size(), 0); |
|
663 |
QVERIFY(m_media->queue().isEmpty()); |
|
664 |
stopPlayback(m_media->state()); |
|
665 |
} |
|
666 |
||
667 |
void tst_MediaObject::testPauseOnFinish() |
|
668 |
{ |
|
669 |
startPlayback(); |
|
670 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 1000); |
|
671 |
QCOMPARE(m_media->state(), Phonon::PlayingState); |
|
672 |
if (m_media->isSeekable() && m_media->totalTime() > 2000) |
|
673 |
m_media->seek(m_media->totalTime() - 2000); |
|
674 |
QTest::waitForSignal(m_media, SIGNAL(finished()), 4000); |
|
675 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 1000); |
|
676 |
||
677 |
QCOMPARE(m_media->state(), Phonon::PausedState); |
|
678 |
connect(m_media, SIGNAL(finished()), m_media, SLOT(stop())); |
|
679 |
m_media->seek(m_media->totalTime() - 2000); |
|
680 |
m_media->play(); |
|
681 |
||
682 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 1000); |
|
683 |
QCOMPARE(m_media->state(), Phonon::PlayingState); |
|
684 |
QTest::waitForSignal(m_media, SIGNAL(finished()), 4000); |
|
685 |
QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 1000); |
|
686 |
stopPlayback(Phonon::StoppedState); |
|
687 |
} |
|
688 |
||
689 |
void tst_MediaObject::testReconnectBetweenTwoMediaObjects(){ |
|
690 |
// Purpose: Test that phonon can handle swithing the same sink |
|
691 |
// between different media objects. |
|
692 |
||
693 |
Phonon::MediaObject obj1; |
|
694 |
Phonon::MediaObject obj2; |
|
695 |
Phonon::AudioOutput audio1; |
|
696 |
Phonon::Path p1 = Phonon::createPath(&obj1, &audio1); |
|
697 |
QVERIFY(p1.isValid()); |
|
698 |
||
699 |
QVERIFY(p1.reconnect(&obj1, &audio1)); |
|
700 |
QVERIFY(p1.isValid()); |
|
701 |
QVERIFY(p1.reconnect(&obj2, &audio1)); |
|
702 |
QVERIFY(p1.isValid()); |
|
703 |
QVERIFY(p1.reconnect(&obj1, &audio1)); |
|
704 |
QVERIFY(p1.isValid()); |
|
705 |
||
706 |
// Repeat the same test while playing: |
|
707 |
QFile file(MEDIA_FILEPATH); |
|
708 |
obj1.setCurrentSource(&file); |
|
709 |
QFile file2(MEDIA_FILEPATH); |
|
710 |
obj2.setCurrentSource(&file2); |
|
711 |
obj1.play(); |
|
712 |
obj2.play(); |
|
713 |
||
714 |
QVERIFY(p1.reconnect(&obj1, &audio1)); |
|
715 |
QVERIFY(p1.isValid()); |
|
716 |
QVERIFY(p1.reconnect(&obj2, &audio1)); |
|
717 |
QVERIFY(p1.isValid()); |
|
718 |
QVERIFY(p1.reconnect(&obj1, &audio1)); |
|
719 |
QVERIFY(p1.isValid()); |
|
720 |
} |
|
721 |
||
722 |
void tst_MediaObject::testPlayOnFinish() |
|
723 |
{ |
|
724 |
connect(m_media, SIGNAL(finished()), SLOT(setMediaAndPlay())); |
|
725 |
startPlayback(); |
|
726 |
if (m_media->isSeekable()) { |
|
727 |
m_media->seek(m_media->totalTime() - SEEK_BACKWARDS); |
|
728 |
QVERIFY(QTest::waitForSignal(this, SIGNAL(continueTestPlayOnFinish()), 6000)); |
|
729 |
} else { |
|
730 |
QVERIFY(QTest::waitForSignal(this, SIGNAL(continueTestPlayOnFinish()), 3000 + m_media->remainingTime())); |
|
731 |
} |
|
732 |
QTest::waitForSignal(m_media, SIGNAL(finished()), 1000); |
|
733 |
stopPlayback(m_media->state()); |
|
734 |
} |
|
735 |
||
736 |
void tst_MediaObject::testTickSignal() |
|
737 |
{ |
|
738 |
QTime start1; |
|
739 |
QTime start2; |
|
740 |
#ifdef Q_OS_WINCE //On Windows CE we only provide ticks above 400ms |
|
741 |
for (qint32 tickInterval = 400; tickInterval <= 1000; tickInterval *= 2) |
|
742 |
#else |
|
743 |
for (qint32 tickInterval = 80; tickInterval <= 500; tickInterval *= 2) |
|
744 |
#endif |
|
745 |
{ |
|
746 |
QSignalSpy tickSpy(m_media, SIGNAL(tick(qint64))); |
|
747 |
//qDebug() << "Test 20 ticks with an interval of" << tickInterval << "ms"; |
|
748 |
m_media->setTickInterval(tickInterval); |
|
749 |
QVERIFY(m_media->tickInterval() <= tickInterval); |
|
750 |
QVERIFY(m_media->tickInterval() >= tickInterval/2); |
|
751 |
QVERIFY(tickSpy.isEmpty()); |
|
752 |
m_media->seek(0); //let's go back to the beginning |
|
753 |
start1.start(); |
|
754 |
startPlayback(); |
|
755 |
start2.start(); |
|
756 |
int lastCount = 0; |
|
757 |
qint64 s1, s2 = start2.elapsed(); |
|
758 |
while (tickSpy.count() < 20 && (m_media->state() == Phonon::PlayingState || m_media->state() == Phonon::BufferingState)) |
|
759 |
{ |
|
760 |
if (tickSpy.count() > lastCount) |
|
761 |
{ |
|
762 |
s1 = start1.elapsed(); |
|
763 |
qint64 tickTime = castQVariantToInt64(tickSpy.last().at(0)); |
|
764 |
lastCount = tickSpy.count(); |
|
765 |
// s1 is the time from before the beginning of the playback to |
|
766 |
// after the tick signal |
|
767 |
// s2 is the time from after the beginning of the playback to |
|
768 |
// before the tick signal |
|
769 |
// so: s2 <= s1 |
|
770 |
QVERIFY(tickTime <= m_media->currentTime()); |
|
771 |
if (s1 + ALLOWED_TICK_INACCURACY < tickTime || s2 - ALLOWED_TICK_INACCURACY > tickTime) { |
|
772 |
qDebug() |
|
773 |
<< "\n" << lastCount << "ticks have been received" |
|
774 |
<< "\ntime from before playback was started to after the tick signal was received:" << s1 << "ms" |
|
775 |
<< "\ntime from after playback was started to before the tick signal was received:" << s2 << "ms" |
|
776 |
<< "\nreported tick time:" << tickTime << "ms" |
|
777 |
<< "\nallowed inaccuracy: +/-" << ALLOWED_TICK_INACCURACY << "ms"; |
|
778 |
for (int i = 0; i < tickSpy.count(); ++i) { |
|
779 |
qDebug() << castQVariantToInt64(tickSpy[i].at(0)); |
|
780 |
} |
|
781 |
} |
|
782 |
QVERIFY(s1 + ALLOWED_TICK_INACCURACY >= tickTime); |
|
783 |
QVERIFY(s2 - ALLOWED_TICK_INACCURACY <= tickTime); |
|
784 |
#ifndef Q_OS_WINCE |
|
785 |
QVERIFY(s1 >= lastCount * m_media->tickInterval()); |
|
786 |
#else |
|
787 |
QVERIFY(s1 >= lastCount * m_media->tickInterval() - ALLOWED_TICK_INACCURACY); |
|
788 |
#endif |
|
789 |
if (s2 > (lastCount + 1) * m_media->tickInterval()) |
|
790 |
QWARN(qPrintable(QString("%1. tick came too late: %2ms elapsed while this tick should have come before %3ms") |
|
791 |
.arg(lastCount).arg(s2).arg((lastCount + 1) * m_media->tickInterval()))); |
|
792 |
} else if (lastCount == 0 && s2 > 20 * m_media->tickInterval()) { |
|
793 |
QFAIL("no tick signals are being received"); |
|
794 |
} |
|
795 |
s2 = start2.elapsed(); |
|
796 |
QTest::waitForSignal(m_media, SIGNAL(tick(qint64)), 2000); |
|
797 |
} |
|
798 |
#ifndef Q_OS_WINCE //the shorter wave file is finished on Windows CE... |
|
799 |
stopPlayback(Phonon::PlayingState); |
|
800 |
#else |
|
801 |
stopPlayback(m_media->state()); |
|
802 |
#endif |
|
803 |
} |
|
804 |
} |
|
805 |
||
806 |
void tst_MediaObject::testSeek() |
|
807 |
{ |
|
808 |
m_media->seek(0); // let's seek back to the beginning |
|
809 |
startPlayback(); |
|
810 |
QTime timer; |
|
811 |
timer.start(); |
|
812 |
qint64 t = m_media->totalTime(); |
|
813 |
qint64 c = m_media->currentTime(); |
|
814 |
qint64 r = m_media->remainingTime(); |
|
815 |
int elapsed = timer.elapsed(); |
|
816 |
if (c + r > t + elapsed || c + r < t - elapsed) { |
|
817 |
// qDebug() << "currentTime:" << c |
|
818 |
// << "remainingTime:" << r |
|
819 |
// << "totalTime:" << t; |
|
820 |
QFAIL("currentTime + remainingTime doesn't come close enough to totalTime"); |
|
821 |
} |
|
822 |
||
823 |
QVERIFY(c + r <= t + elapsed); |
|
824 |
QVERIFY(c + r >= t - elapsed); |
|
825 |
if (m_media->isSeekable()) |
|
826 |
if (r > 0) |
|
827 |
{ |
|
828 |
m_media->setTickInterval(20); |
|
829 |
qint64 s = c + r / 2; |
|
830 |
testOneSeek(s); |
|
831 |
||
832 |
s /= 2; |
|
833 |
testOneSeek(s); |
|
834 |
s = s * 3 / 2; |
|
835 |
testOneSeek(s); |
|
836 |
||
837 |
pausePlayback(); |
|
838 |
||
839 |
s = s * 3 / 2; |
|
840 |
testOneSeek(s); |
|
841 |
s /= 2; |
|
842 |
testOneSeek(s); |
|
843 |
||
844 |
m_media->setTickInterval(0); |
|
845 |
||
846 |
||
847 |
stopPlayback(Phonon::PausedState); |
|
848 |
return; |
|
849 |
} |
|
850 |
else |
|
851 |
QWARN("didn't test seeking as the MediaObject reported a remaining size <= 0"); |
|
852 |
else |
|
853 |
QWARN("didn't test seeking as the MediaObject is not seekable"); |
|
854 |
stopPlayback(Phonon::PlayingState); |
|
855 |
} |
|
856 |
||
857 |
||
858 |
void tst_MediaObject::setMediaAndPlay() |
|
859 |
{ |
|
860 |
m_stateChangedSignalSpy->clear(); |
|
861 |
QCOMPARE(m_stateChangedSignalSpy->count(), 0); |
|
862 |
||
863 |
QSignalSpy totalTimeChangedSignalSpy(m_media, SIGNAL(totalTimeChanged(qint64))); |
|
864 |
QVERIFY(m_media->currentSource().type() != MediaSource::Invalid); |
|
865 |
Phonon::State state = m_media->state(); |
|
866 |
QVERIFY(state == Phonon::StoppedState || state == Phonon::PlayingState || Phonon::PausedState); |
|
867 |
m_media->setCurrentSource(m_url); |
|
868 |
// before calling play() we better make sure that if play() finishes very fast that we don't get |
|
869 |
// called again |
|
870 |
disconnect(m_media, SIGNAL(finished()), this, SLOT(setMediaAndPlay())); |
|
871 |
state = m_media->state(); |
|
872 |
startPlayback2(state); |
|
873 |
||
874 |
emit continueTestPlayOnFinish(); |
|
875 |
} |
|
876 |
||
877 |
void tst_MediaObject::testPlayBeforeFinish() |
|
878 |
{ |
|
879 |
startPlayback(); |
|
880 |
QCOMPARE(m_stateChangedSignalSpy->size(), 0); |
|
881 |
Phonon::State state = m_media->state(); |
|
882 |
QCOMPARE(state, Phonon::PlayingState); |
|
883 |
m_media->setCurrentSource(m_url); |
|
884 |
m_media->play(); |
|
885 |
if (m_stateChangedSignalSpy->isEmpty()) { |
|
886 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 4000)); |
|
887 |
} |
|
888 |
// first (optional) state to reach is StoppedState |
|
889 |
QList<QVariant> args = m_stateChangedSignalSpy->takeFirst(); |
|
890 |
Phonon::State oldstate = qvariant_cast<Phonon::State>(args.at(1)); |
|
891 |
QCOMPARE(oldstate, state); |
|
892 |
state = qvariant_cast<Phonon::State>(args.at(0)); |
|
893 |
if (state == Phonon::StoppedState) { |
|
894 |
if (m_stateChangedSignalSpy->isEmpty()) { |
|
895 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 4000)); |
|
896 |
} |
|
897 |
args = m_stateChangedSignalSpy->takeFirst(); |
|
898 |
oldstate = qvariant_cast<Phonon::State>(args.at(1)); |
|
899 |
QCOMPARE(oldstate, state); |
|
900 |
state = qvariant_cast<Phonon::State>(args.at(0)); |
|
901 |
} |
|
902 |
// next LoadingState |
|
903 |
QCOMPARE(state, Phonon::LoadingState); |
|
904 |
if (m_stateChangedSignalSpy->isEmpty()) { |
|
905 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 4000)); |
|
906 |
} |
|
907 |
// next either BufferingState or PlayingState |
|
908 |
args = m_stateChangedSignalSpy->takeFirst(); |
|
909 |
oldstate = qvariant_cast<Phonon::State>(args.at(1)); |
|
910 |
QCOMPARE(oldstate, state); |
|
911 |
state = qvariant_cast<Phonon::State>(args.at(0)); |
|
912 |
if (state == Phonon::BufferingState) { |
|
913 |
if (m_stateChangedSignalSpy->isEmpty()) { |
|
914 |
QVERIFY(QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 4000)); // buffering can take a while |
|
915 |
} |
|
916 |
args = m_stateChangedSignalSpy->takeFirst(); |
|
917 |
oldstate = qvariant_cast<Phonon::State>(args.at(1)); |
|
918 |
QCOMPARE(oldstate, state); |
|
919 |
state = qvariant_cast<Phonon::State>(args.at(0)); |
|
920 |
} |
|
921 |
#ifdef Q_WS_MAC |
|
922 |
// m_media->setCurrentSource(m_url) in phonon frontend will always call |
|
923 |
// 'stop' on the backend before calling 'setSource'. So the QT7 backend |
|
924 |
// goes into stop, and naturally remains there after setting the new source. |
|
925 |
// So going into playing state cannot happend when the backend is synchronized. |
|
926 |
// Thats the reason for the ifdef. |
|
927 |
QCOMPARE(state, Phonon::StoppedState); |
|
928 |
#else |
|
929 |
stopPlayback(Phonon::PlayingState); |
|
930 |
#endif |
|
931 |
} |
|
932 |
||
933 |
void tst_MediaObject::cleanupTestCase() |
|
934 |
{ |
|
935 |
if (m_stateChangedSignalSpy) |
|
936 |
delete m_stateChangedSignalSpy; |
|
937 |
if (m_media) |
|
938 |
delete m_media; |
|
939 |
#ifdef Q_OS_WINCE |
|
940 |
QTest::qWait(200); |
|
941 |
#endif |
|
942 |
if (!m_tmpFileName.isNull()) { |
|
943 |
QVERIFY(QFile::remove(m_tmpFileName)); |
|
944 |
} |
|
945 |
} |
|
946 |
||
947 |
void tst_MediaObject::_testOneSeek(qint64 seekTo) |
|
948 |
{ |
|
949 |
qint64 t = m_media->totalTime(); |
|
950 |
qint64 oldTime = m_media->currentTime(); |
|
951 |
if (oldTime == seekTo) { |
|
952 |
return; |
|
953 |
} |
|
954 |
||
955 |
QTime seekDuration; |
|
956 |
seekDuration.start(); |
|
957 |
m_media->seek(seekTo); |
|
958 |
||
959 |
QVERIFY(oldTime == 0 || seekTo == 0 || m_media->currentTime() != 0); |
|
960 |
||
961 |
int bufferingTime = 0; |
|
962 |
Phonon::State s = m_media->state(); |
|
963 |
QTime timer; |
|
964 |
if (s == Phonon::BufferingState) { |
|
965 |
timer.start(); |
|
966 |
} |
|
967 |
QEventLoop loop; |
|
968 |
connect(m_media, SIGNAL(tick(qint64)), &loop, SLOT(quit())); |
|
969 |
connect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), &loop, SLOT(quit())); |
|
970 |
||
971 |
qint64 c = m_media->currentTime(); |
|
972 |
qint64 r = m_media->remainingTime(); |
|
973 |
int elapsed = 0; |
|
974 |
while (qAbs(c - seekTo) > ALLOWED_SEEK_INACCURACY){ |
|
975 |
QTimer::singleShot(ALLOWED_TIME_FOR_SEEKING, &loop, SLOT(quit())); |
|
976 |
||
977 |
loop.exec(); |
|
978 |
c = m_media->currentTime(); |
|
979 |
r = m_media->remainingTime(); |
|
980 |
if (s == Phonon::BufferingState) { |
|
981 |
bufferingTime += timer.restart(); |
|
982 |
} else { |
|
983 |
timer.start(); |
|
984 |
} |
|
985 |
s = m_media->state(); |
|
986 |
elapsed = seekDuration.elapsed(); |
|
987 |
QVERIFY(elapsed - bufferingTime < (ALLOWED_TIME_FOR_SEEKING + SEEKING_TOLERANCE)); |
|
988 |
} |
|
989 |
||
990 |
QVERIFY(c >= seekTo - ALLOWED_SEEK_INACCURACY); |
|
991 |
if (s == Phonon::PausedState) { |
|
992 |
QVERIFY(bufferingTime == 0); |
|
993 |
elapsed = 0; |
|
994 |
} |
|
995 |
if (c > seekTo + ALLOWED_SEEK_INACCURACY + elapsed - bufferingTime) { |
|
996 |
QFAIL("currentTime is greater than the requested time + the time that elapsed since the seek started."); |
|
997 |
} |
|
998 |
if (c + r > t + 200 || c + r < t - 200) { |
|
999 |
QFAIL("currentTime + remainingTime doesn't come close enough to totalTime"); |
|
1000 |
} |
|
1001 |
m_success = true; |
|
1002 |
} |
|
1003 |
||
1004 |
void tst_MediaObject::volumeSliderMuteVisibility() |
|
1005 |
{ |
|
1006 |
//this test doesn't really belong to mediaobject |
|
1007 |
// ### see if we should create a realy Phonon::VolumeSlider autotest |
|
1008 |
Phonon::VolumeSlider slider; |
|
1009 |
QVERIFY(slider.isMuteVisible()); // that is the default value |
|
1010 |
slider.setMuteVisible(true); |
|
1011 |
QVERIFY(slider.isMuteVisible()); |
|
1012 |
||
1013 |
//let's check that changing the visibility of the slider itself |
|
1014 |
//doesn't change what the slider reports |
|
1015 |
slider.setVisible(false); |
|
1016 |
QVERIFY(slider.isMuteVisible()); |
|
1017 |
slider.setVisible(true); |
|
1018 |
||
1019 |
slider.setMuteVisible(false); |
|
1020 |
QVERIFY(!slider.isMuteVisible()); |
|
1021 |
slider.setMuteVisible(true); |
|
1022 |
QVERIFY(slider.isMuteVisible()); |
|
1023 |
} |
|
1024 |
||
1025 |
||
1026 |
#endif //QT_NO_PHONON |
|
1027 |
||
1028 |
||
1029 |
QTEST_MAIN(tst_MediaObject) |
|
1030 |
||
1031 |
#include "tst_mediaobject.moc" |
|
1032 |
// vim: sw=4 ts=4 |