191 static qint32 castQVariantToInt32(const QVariant &variant) |
191 static qint32 castQVariantToInt32(const QVariant &variant) |
192 { |
192 { |
193 return *reinterpret_cast<const qint32 *>(variant.constData()); |
193 return *reinterpret_cast<const qint32 *>(variant.constData()); |
194 } |
194 } |
195 |
195 |
196 static const char *const red = "\033[0;31m"; |
|
197 static const char *const green = "\033[0;32m"; |
|
198 static const char *const yellow = "\033[0;33m"; |
|
199 static const char *const blue = "\033[0;34m"; |
|
200 static const char *const purple = "\033[0;35m"; |
|
201 static const char *const cyan = "\033[0;36m"; |
|
202 static const char *const white = "\033[0;37m"; |
|
203 static const char *const normal = "\033[0m"; |
|
204 |
|
205 void tst_MediaObject::stateChanged(Phonon::State newstate, Phonon::State oldstate) |
196 void tst_MediaObject::stateChanged(Phonon::State newstate, Phonon::State oldstate) |
206 { |
197 { |
207 if (newstate == Phonon::ErrorState) { |
198 if (newstate == Phonon::ErrorState) |
208 QWARN(QByteArray(QByteArray(red) + ".......................................................... ") + QByteArray(QTest::toString(oldstate)) + " to " + QByteArray(QTest::toString(newstate)) + normal); |
199 QWARN(QByteArray(QByteArray(QTest::toString(oldstate)) + " to " + QByteArray(QTest::toString(newstate)))); |
209 } else { |
|
210 //qDebug() << ".........................................................." << cyan << QTest::toString(oldstate) << "to" << QTest::toString(newstate) << normal; |
|
211 } |
|
212 } |
200 } |
213 |
201 |
214 void tst_MediaObject::testPlayFromResource() |
202 void tst_MediaObject::testPlayFromResource() |
215 { |
203 { |
216 #ifdef Q_OS_SYMBIAN |
204 #ifdef Q_OS_SYMBIAN |
217 QSKIP("Not implemented yet.", SkipAll); |
205 QSKIP("Not implemented yet.", SkipAll); |
218 return; |
206 #else |
219 #endif |
|
220 |
|
221 QFile file(MEDIA_FILEPATH); |
207 QFile file(MEDIA_FILEPATH); |
222 MediaObject media; |
208 MediaObject media; |
223 media.setCurrentSource(&file); |
209 media.setCurrentSource(&file); |
224 QVERIFY(media.state() != Phonon::ErrorState); |
210 QVERIFY(media.state() != Phonon::ErrorState); |
225 if (media.state() != Phonon::StoppedState) |
211 if (media.state() != Phonon::StoppedState) |
227 QCOMPARE(media.state(), Phonon::StoppedState); |
213 QCOMPARE(media.state(), Phonon::StoppedState); |
228 media.play(); |
214 media.play(); |
229 if (media.state() != Phonon::PlayingState) |
215 if (media.state() != Phonon::PlayingState) |
230 QTest::waitForSignal(&media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
216 QTest::waitForSignal(&media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
231 QCOMPARE(media.state(), Phonon::PlayingState); |
217 QCOMPARE(media.state(), Phonon::PlayingState); |
|
218 #endif |
232 } |
219 } |
233 |
220 |
234 void tst_MediaObject::testPlayIllegalFile() |
221 void tst_MediaObject::testPlayIllegalFile() |
235 { |
222 { |
236 QString filename = QDir::tempPath() + QString("/test.wav"); |
223 QString filename = QDir::tempPath() + QString("/test.wav"); |
261 } |
248 } |
262 if (m_media->state() == Phonon::LoadingState) { |
249 if (m_media->state() == Phonon::LoadingState) { |
263 QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
250 QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
264 } |
251 } |
265 m_stateChangedSignalSpy->clear(); |
252 m_stateChangedSignalSpy->clear(); |
|
253 } |
|
254 |
|
255 // Ensure that m_media is in StoppedState |
|
256 if (m_media->state() != Phonon::StoppedState) { |
|
257 m_media->stop(); |
|
258 QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
|
259 QCOMPARE(m_media->state(), Phonon::StoppedState); |
266 } |
260 } |
267 } |
261 } |
268 |
262 |
269 void tst_MediaObject::cleanup() |
263 void tst_MediaObject::cleanup() |
270 { |
264 { |
577 const MediaSource sdpSource(sdpFile); |
571 const MediaSource sdpSource(sdpFile); |
578 m_media->setCurrentSource(sdpSource); |
572 m_media->setCurrentSource(sdpSource); |
579 if (m_media->state() != Phonon::StoppedState) |
573 if (m_media->state() != Phonon::StoppedState) |
580 QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
574 QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State)), 10000); |
581 |
575 |
582 // At this point we're in error state due to absent media, but it has now loaded the SDP: |
576 // MediaObject should have loaded the SDP, but be in error state due to absent media |
583 QCOMPARE(m_media->errorString(), QString::fromLatin1("Buffering clip failed: Unknown error (-39)")); |
577 const bool stateMatch = (m_media->state() == Phonon::ErrorState); |
584 |
578 const bool errorStringMatch = (m_media->errorString() == QString::fromLatin1("Loading clip failed: Unknown error (-39)")); |
585 // We cannot play the SDP, we can neither attempt to play it, because we |
579 |
586 // won't get a state change from ErrorState to ErrorState, and hence block |
580 // Ensure that m_media is back in ground state prior to starting next test step |
587 // on a never occuring signal. |
|
588 m_media->setCurrentSource(oldSource); |
581 m_media->setCurrentSource(oldSource); |
|
582 if (m_media->state() != Phonon::StoppedState) |
|
583 QTest::waitForSignal(m_media, SIGNAL(stateChanged(Phonon::State, Phonon::State))); |
|
584 QCOMPARE(m_media->state(), Phonon::StoppedState); |
|
585 |
|
586 QVERIFY(stateMatch); |
|
587 QVERIFY(errorStringMatch); |
589 |
588 |
590 #else |
589 #else |
591 QSKIP("Unsupported on this platform.", SkipAll); |
590 QSKIP("Unsupported on this platform.", SkipAll); |
592 #endif |
591 #endif |
593 } |
592 } |