Commit 1e8f719b authored by Olivier Aubert's avatar Olivier Aubert

python-ctypes: implement comparison operators for enum classes

parent 3a38a0e0
* Investigate memory management
* Write a test suite
* Support multiple VLC versions: define a front-end module which will
load the appropriate versionned module from a subdirectory.
......@@ -478,7 +478,7 @@ class PythonGenerator(object):
conv[k]=n
for k, v in values:
self.output(" %s=%s" % (conv[k], v))
self.output(" %s=ctypes.c_uint(%s)" % (conv[k], v))
self.output(" _names={")
for k, v in values:
......@@ -488,6 +488,13 @@ class PythonGenerator(object):
self.output("""
def __repr__(self):
return ".".join((self.__class__.__module__, self.__class__.__name__, self._names[self.value]))
def __eq__(self, other):
return (isinstance(other, ctypes.c_uint) and self.value == other.value)
def __ne__(self, other):
return not self.__eq__(other)
""")
def output_ctypes(self, rtype, method, params, comment):
......
......@@ -37,37 +37,37 @@ class TestVLCAPI(unittest.TestCase):
# failure, check that the reason is not a change in the .h
# definitions.
def test_enum_event_type(self):
self.assertEqual(vlc.EventType.MediaStateChanged, 5)
self.assertEqual(vlc.EventType.MediaStateChanged.value, 5)
def test_enum_meta(self):
self.assertEqual(vlc.Meta.Description, 6)
self.assertEqual(vlc.Meta.Description.value, 6)
def test_enum_state(self):
self.assertEqual(vlc.State.Playing, 3)
self.assertEqual(vlc.State.Playing.value, 3)
def test_enum_media_option(self):
self.assertEqual(vlc.MediaOption.unique, 256)
self.assertEqual(vlc.MediaOption.unique.value, 256)
def test_enum_playback_mode(self):
self.assertEqual(vlc.PlaybackMode.repeat, 2)
self.assertEqual(vlc.PlaybackMode.repeat.value, 2)
def test_enum_marquee_int_option(self):
self.assertEqual(vlc.VideoMarqueeIntOption.Size, 5)
self.assertEqual(vlc.VideoMarqueeIntOption.Size.value, 5)
def test_enum_output_device_type(self):
self.assertEqual(vlc.AudioOutputDeviceTypes._2F2R, 4)
self.assertEqual(vlc.AudioOutputDeviceTypes._2F2R.value, 4)
def test_enum_output_channel(self):
self.assertEqual(vlc.AudioOutputChannel.Dolbys, 5)
self.assertEqual(vlc.AudioOutputChannel.Dolbys.value, 5)
def test_enum_position_origin(self):
self.assertEqual(vlc.PositionOrigin.ModuloPosition, 2)
self.assertEqual(vlc.PositionOrigin.ModuloPosition.value, 2)
def test_enum_position_key(self):
self.assertEqual(vlc.PositionKey.MediaTime, 2)
self.assertEqual(vlc.PositionKey.MediaTime.value, 2)
def test_enum_player_status(self):
self.assertEqual(vlc.PlayerStatus.StopStatus, 5)
self.assertEqual(vlc.PlayerStatus.StopStatus.value, 5)
# Basic MediaControl tests
def test_mediacontrol_creation(self):
......@@ -101,5 +101,11 @@ class TestVLCAPI(unittest.TestCase):
p=i.media_player_new(mrl)
self.assertEqual(p.get_media().get_mrl(), mrl)
def test_libvlc_player_state(self):
mrl='/tmp/foo.avi'
i=vlc.Instance()
p=i.media_player_new(mrl)
self.assertEqual(p.get_state(), vlc.State.Ended)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment