]> git.sesse.net Git - vlc/blob - bindings/python-ctypes/test.py
phonon: Allow building against kdesupport libphonon.
[vlc] / bindings / python-ctypes / test.py
1 #! /usr/bin/python
2
3 #
4 # Code generator for python ctypes bindings for VLC
5 # Copyright (C) 2009 the VideoLAN team
6 # $Id: $
7 #
8 # Authors: Olivier Aubert <olivier.aubert at liris.cnrs.fr>
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 #
24
25 """Unittest module.
26 """
27
28 import unittest
29 import vlc
30
31 class TestVLCAPI(unittest.TestCase):
32     #def setUp(self):
33     #    self.seq = range(10)
34     #self.assert_(element in self.seq)
35
36     # We check enum definitions against hardcoded values. In case of
37     # failure, check that the reason is not a change in the .h
38     # definitions.
39     def test_enum_event_type(self):
40         self.assertEqual(vlc.EventType.MediaStateChanged.value, 5)
41
42     def test_enum_meta(self):
43         self.assertEqual(vlc.Meta.Description.value, 6)
44
45     def test_enum_state(self):
46         self.assertEqual(vlc.State.Playing.value, 3)
47
48     def test_enum_media_option(self):
49         self.assertEqual(vlc.MediaOption.unique.value, 256)
50
51     def test_enum_playback_mode(self):
52         self.assertEqual(vlc.PlaybackMode.repeat.value, 2)
53
54     def test_enum_marquee_int_option(self):
55         self.assertEqual(vlc.VideoMarqueeIntOption.Size.value, 5)
56
57     def test_enum_output_device_type(self):
58         self.assertEqual(vlc.AudioOutputDeviceTypes._2F2R.value, 4)
59
60     def test_enum_output_channel(self):
61         self.assertEqual(vlc.AudioOutputChannel.Dolbys.value, 5)
62
63     def test_enum_position_origin(self):
64         self.assertEqual(vlc.PositionOrigin.ModuloPosition.value, 2)
65
66     def test_enum_position_key(self):
67         self.assertEqual(vlc.PositionKey.MediaTime.value, 2)
68
69     def test_enum_player_status(self):
70         self.assertEqual(vlc.PlayerStatus.StopStatus.value, 5)
71
72     # Basic MediaControl tests
73     def test_mediacontrol_creation(self):
74         mc=vlc.MediaControl()
75         self.assert_(mc)
76
77     def test_mediacontrol_initial_mrl(self):
78         mc=vlc.MediaControl()
79         self.assertEqual(mc.get_mrl(), '')
80
81     def test_mediacontrol_set_mrl(self):
82         mrl='/tmp/foo.avi'
83         mc=vlc.MediaControl()
84         mc.set_mrl(mrl)
85         self.assertEqual(mc.get_mrl(), mrl)
86
87     def test_mediacontrol_position(self):
88         p=vlc.MediaControlPosition(value=2,
89                                    origin=vlc.PositionOrigin.RelativePosition,
90                                    key=vlc.PositionKey.MediaTime)
91         self.assertEqual(p.value, 2)
92
93     def test_mediacontrol_position_shortcut(self):
94         p=vlc.MediaControlPosition(2)
95         self.assertEqual(p.value, 2)
96         self.assertEqual(p.key, vlc.PositionKey.MediaTime)
97         self.assertEqual(p.origin, vlc.PositionOrigin.AbsolutePosition)
98
99     def test_mediacontrol_get_media_position(self):
100         mc=vlc.MediaControl()
101         p=mc.get_media_position()
102         self.assertEqual(p.value, -1)
103
104     def test_mediacontrol_get_stream_information(self):
105         mc=vlc.MediaControl()
106         s=mc.get_stream_information()
107         self.assertEqual(s.position, 0)
108         self.assertEqual(s.length, 0)
109
110     # Basic libvlc tests
111     def test_instance_creation(self):
112         i=vlc.Instance()
113         self.assert_(i)
114
115     def test_libvlc_media(self):
116         mrl='/tmp/foo.avi'
117         i=vlc.Instance()
118         m=i.media_new(mrl)
119         self.assertEqual(m.get_mrl(), mrl)
120
121     def test_libvlc_player(self):
122         mrl='/tmp/foo.avi'
123         i=vlc.Instance()
124         p=i.media_player_new(mrl)
125         self.assertEqual(p.get_media().get_mrl(), mrl)
126
127     def test_libvlc_player_state(self):
128         mrl='/tmp/foo.avi'
129         i=vlc.Instance()
130         p=i.media_player_new(mrl)
131         self.assertEqual(p.get_state(), vlc.State.Ended)
132
133     def test_libvlc_logger(self):
134         i=vlc.Instance()
135         l=i.log_open()
136         l.clear()
137         self.assertEqual(l.count(), 0)
138         l.close()
139
140     def test_libvlc_logger_clear(self):
141         i=vlc.Instance()
142         l=i.log_open()
143         l.clear()
144         self.assertEqual(l.count(), 0)
145         l.close()
146
147     def test_libvlc_logger(self):
148         i=vlc.Instance()
149         i.set_log_verbosity(3)
150         l=i.log_open()
151         # This should generate a log message
152         i.add_intf('dummy')
153         self.assertNotEqual(l.count(), 0)
154         for m in l:
155             # Ensure that messages can be read.
156             self.assertNotEqual(len(m.message), 0)
157         l.close()
158
159 if __name__ == '__main__':
160     unittest.main()