aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phonon/basic_playing_test.py
blob: 4eb2ccdd7b9ae8e9d1a6d45a7799863e0e8d6b58 (plain)
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

import os
import unittest

from PySide import QtCore
from PySide import phonon

from helper import UsesQCoreApplication

# XXX Hack to get the correct filename
example_file = os.path.join(os.path.dirname(__file__),'tone.ogg')

class TestSimplePlaying(UsesQCoreApplication):
    def setUp(self):
        super(TestSimplePlaying, self).setUp()
        self.app.setApplicationName('Dummy')
        self.source = phonon.Phonon.MediaSource(example_file)
        self.media = phonon.Phonon.MediaObject()
        self.media.setCurrentSource(self.source)

        QtCore.QObject.connect(self.media,
                QtCore.SIGNAL('finished()'),
                self.app,
                QtCore.SLOT('quit()'))

        self.called = False

        # prevent locking with:
        # request to play a stream, but no valid audio ...
        self.output = phonon.Phonon.AudioOutput()
        self.path = phonon.Phonon.createPath(self.media, self.output)

    def tearDown(self):
        super(TestSimplePlaying, self).tearDown()
        del self.path
        del self.output
        del self.media
        del self.source

    def testFinishedSignal(self):
        # Check for ogg support before playing it
        if (phonon.Phonon.BackendCapabilities.isMimeTypeAvailable('audio/ogg')):
            # Should pass if finished() is called
            self.media.play()
            self.app.exec_()
        else:
            print 'Ogg format not supported! Playback test skipped!'

    def testMediaSource(self):
        self.assertEqual(self.media.currentSource(), self.source)

    def testPathCreation(self):
        # FIXME Both functions below are not exported by PyQt4
        self.assertEqual(self.path.sink(), self.output)
        self.assertEqual(self.path.source(), self.media)

    def state_cb(self, newState, OldState):
        self.called = True

    def testStateChanged(self):
        # Check for ogg support before playing it
        if (phonon.Phonon.BackendCapabilities.isMimeTypeAvailable('audio/ogg')):
            QtCore.QObject.connect(self.media,
                QtCore.SIGNAL('stateChanged(Phonon::State, Phonon::State)'),
                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__':
    unittest.main()