[vlc-devel] commit: python-ctypes: implement comparison operators for enum classes ( Olivier Aubert )

git version control git at videolan.org
Thu Sep 3 10:54:03 CEST 2009


vlc | branch: master | Olivier Aubert <olivier.aubert at liris.cnrs.fr> | Thu Sep  3 10:31:36 2009 +0200| [1e8f719b45252f2512fee56e4cf1ae906cc7ea75] | committer: Olivier Aubert 

python-ctypes: implement comparison operators for enum classes

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1e8f719b45252f2512fee56e4cf1ae906cc7ea75
---

 bindings/python-ctypes/TODO        |    2 --
 bindings/python-ctypes/generate.py |    9 ++++++++-
 bindings/python-ctypes/test.py     |   28 +++++++++++++++++-----------
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/bindings/python-ctypes/TODO b/bindings/python-ctypes/TODO
index 087d87b..07ddd07 100644
--- a/bindings/python-ctypes/TODO
+++ b/bindings/python-ctypes/TODO
@@ -1,6 +1,4 @@
 * 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.
diff --git a/bindings/python-ctypes/generate.py b/bindings/python-ctypes/generate.py
index 355536f..a1870e0 100755
--- a/bindings/python-ctypes/generate.py
+++ b/bindings/python-ctypes/generate.py
@@ -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):
diff --git a/bindings/python-ctypes/test.py b/bindings/python-ctypes/test.py
index bd0c4a3..97899fa 100755
--- a/bindings/python-ctypes/test.py
+++ b/bindings/python-ctypes/test.py
@@ -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()




More information about the vlc-devel mailing list