[pypy-commit] cffi default: Some tests for issue19.

arigo noreply at buildbot.pypy.org
Thu Aug 23 12:17:56 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r875:bbd4eb593724
Date: 2012-08-23 12:17 +0200
http://bitbucket.org/cffi/cffi/changeset/bbd4eb593724/

Log:	Some tests for issue19.

diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -806,6 +806,37 @@
     """)
     assert lib.foo_func(lib.BB) == "BB"
 
+def test_enum_values():
+    ffi = FFI()
+    ffi.cdef("enum enum1_e { AA, BB };")
+    lib = ffi.verify("enum enum1_e { AA, BB };")
+    assert lib.AA == 0
+    assert lib.BB == 1
+    assert ffi.string(ffi.cast("enum enum1_e", 1)) == 'BB'
+
+def test_typedef_complete_enum():
+    ffi = FFI()
+    ffi.cdef("typedef enum { AA, BB } enum1_t;")
+    lib = ffi.verify("typedef enum { AA, BB } enum1_t;")
+    assert ffi.string(ffi.cast("enum enum1_e", 1)) == 'BB'
+    assert lib.AA == 0
+    assert lib.BB == 1
+
+def test_typedef_broken_complete_enum():
+    ffi = FFI()
+    ffi.cdef("typedef enum { AA, BB } enum1_t;")
+    py.test.raises(VerificationError, ffi.verify,
+                   "typedef enum { AA, CC, BB } enum1_t;")
+
+def test_typedef_incomplete_enum():
+    ffi = FFI()
+    ffi.cdef("typedef enum { AA, BB, ... } enum1_t;")
+    lib = ffi.verify("typedef enum { AA, CC, BB } enum1_t;")
+    assert ffi.string(ffi.cast("enum enum1_e", 1)) == '#1'
+    assert ffi.string(ffi.cast("enum enum1_e", 2)) == 'BB'
+    assert lib.AA == 0
+    assert lib.BB == 2
+
 def test_callback_calling_convention():
     py.test.skip("later")
     if sys.platform != 'win32':


More information about the pypy-commit mailing list