Refactoring to Phonon basic playing test.

Also replaced the ogg audio tone file for a wav one.

Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Reviewed by Renato Araújo <renato.filho@openbossa.org>
This commit is contained in:
Marcelo Lira 2011-01-06 16:23:16 -03:00 • committed by Hugo Parente Lima
commit 42e52dec9c
3 changed files with 26 additions and 32 deletions

View file

@ -1,34 +1,35 @@
import os import os
import unittest import unittest
from PySide.phonon import Phonon
from PySide import QtCore
from PySide import phonon
from helper import UsesQCoreApplication from helper import UsesQCoreApplication
# XXX Hack to get the correct filename sample_file = os.path.join(os.path.dirname(__file__), 'tone.wav')
example_file = os.path.join(os.path.dirname(__file__),'tone.ogg')
def checkBackendCapabilities(func):
def function(self, *args, **kw):
if Phonon.BackendCapabilities.isMimeTypeAvailable('audio/x-wav'):
func(self, *args, **kw)
else:
print 'Wav format not supported! Playback test skipped!'
return function
class TestSimplePlaying(UsesQCoreApplication): class TestSimplePlaying(UsesQCoreApplication):
def setUp(self): def setUp(self):
super(TestSimplePlaying, self).setUp() super(TestSimplePlaying, self).setUp()
self.app.setApplicationName('Dummy') self.app.setApplicationName('Dummy')
self.source = phonon.Phonon.MediaSource(example_file) self.source = Phonon.MediaSource(sample_file)
self.media = phonon.Phonon.MediaObject() self.media = Phonon.MediaObject()
self.media.setCurrentSource(self.source) self.media.setCurrentSource(self.source)
QtCore.QObject.connect(self.media, self.media.finished.connect(self.app.quit)
QtCore.SIGNAL('finished()'),
self.app,
QtCore.SLOT('quit()'))
self.called = False self.called = False
# prevent locking with: # prevent locking with:
# request to play a stream, but no valid audio ... # request to play a stream, but no valid audio ...
self.output = phonon.Phonon.AudioOutput() self.output = Phonon.AudioOutput()
self.path = phonon.Phonon.createPath(self.media, self.output) self.path = Phonon.createPath(self.media, self.output)
def tearDown(self): def tearDown(self):
super(TestSimplePlaying, self).tearDown() super(TestSimplePlaying, self).tearDown()
@ -37,14 +38,11 @@ class TestSimplePlaying(UsesQCoreApplication):
del self.media del self.media
del self.source del self.source
@checkBackendCapabilities
def testFinishedSignal(self): def testFinishedSignal(self):
# Check for ogg support before playing it # Should pass if finished() is called
if (phonon.Phonon.BackendCapabilities.isMimeTypeAvailable('audio/ogg')): self.media.play()
# Should pass if finished() is called self.app.exec_()
self.media.play()
self.app.exec_()
else:
print 'Ogg format not supported! Playback test skipped!'
def testMediaSource(self): def testMediaSource(self):
self.assertEqual(self.media.currentSource(), self.source) self.assertEqual(self.media.currentSource(), self.source)
@ -57,18 +55,14 @@ class TestSimplePlaying(UsesQCoreApplication):
def state_cb(self, newState, OldState): def state_cb(self, newState, OldState):
self.called = True self.called = True
@checkBackendCapabilities
def testStateChanged(self): def testStateChanged(self):
# Check for ogg support before playing it self.media.stateChanged['Phonon::State', 'Phonon::State'].connect(self.state_cb)
if (phonon.Phonon.BackendCapabilities.isMimeTypeAvailable('audio/ogg')): self.media.play()
QtCore.QObject.connect(self.media, self.app.exec_()
QtCore.SIGNAL('stateChanged(Phonon::State, Phonon::State)'), self.assert_(self.called)
self.state_cb)
self.media.play()
self.app.exec_()
self.assert_(self.called)
else:
print 'Ogg format not supported! Playback test skipped!'
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Binary file not shown.

BIN
tests/phonon/tone.wav Normal file

Binary file not shown.