[pypy-commit] cffi cffi-1.0: more tests

arigo noreply at buildbot.pypy.org
Sat May 16 10:58:55 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r2005:29bae4591d1c
Date: 2015-05-16 10:26 +0200
http://bitbucket.org/cffi/cffi/changeset/29bae4591d1c/

Log:	more tests

diff --git a/testing/cffi1/test_re_python.py b/testing/cffi1/test_re_python.py
--- a/testing/cffi1/test_re_python.py
+++ b/testing/cffi1/test_re_python.py
@@ -10,7 +10,8 @@
     #define FOOBAR (-42)
     int add42(int x) { return x + 42; }
     struct foo_s;
-    struct bar_s { int x; signed char a[]; };
+    typedef struct bar_s { int x; signed char a[]; } bar_t;
+    enum foo_e { AA, BB, CC };
     """
     tmpdir = udir.join('test_re_python')
     tmpdir.ensure(dir=1)
@@ -25,7 +26,8 @@
     #define FOOBAR -42
     int add42(int);
     struct foo_s;
-    struct bar_s { int x; signed char a[]; };
+    typedef struct bar_s { int x; signed char a[]; } bar_t;
+    enum foo_e { AA, BB, CC };
     """)
     ffi.set_source('re_python_pysrc', None)
     ffi.emit_python_code(str(tmpdir.join('re_python_pysrc.py')))
@@ -54,7 +56,14 @@
 
 def test_nonopaque_struct():
     from re_python_pysrc import ffi
-    p = ffi.new("struct bar_s *", [5, "foobar"])
-    assert p.x == 5
-    assert p.a[0] == ord('f')
-    assert p.a[5] == ord('r')
+    for p in [ffi.new("struct bar_s *", [5, "foobar"]),
+              ffi.new("bar_t *", [5, "foobar"])]:
+        assert p.x == 5
+        assert p.a[0] == ord('f')
+        assert p.a[5] == ord('r')
+
+def test_enum():
+    from re_python_pysrc import ffi
+    assert ffi.integer_const("BB") == 1
+    e = ffi.cast("enum foo_e", 2)
+    assert ffi.string(e) == "CC"


More information about the pypy-commit mailing list