[pypy-commit] cffi cffi-1.0: more tests
arigo
noreply at buildbot.pypy.org
Sat May 16 10:58:54 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r2004:d89b58d30fff
Date: 2015-05-16 10:24 +0200
http://bitbucket.org/cffi/cffi/changeset/d89b58d30fff/
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
@@ -1,4 +1,5 @@
import sys
+import py
from cffi import FFI
from cffi import recompiler, ffiplatform
from testing.udir import udir
@@ -8,6 +9,8 @@
SRC = """
#define FOOBAR (-42)
int add42(int x) { return x + 42; }
+ struct foo_s;
+ struct bar_s { int x; signed char a[]; };
"""
tmpdir = udir.join('test_re_python')
tmpdir.ensure(dir=1)
@@ -21,6 +24,8 @@
ffi.cdef("""
#define FOOBAR -42
int add42(int);
+ struct foo_s;
+ struct bar_s { int x; signed char a[]; };
""")
ffi.set_source('re_python_pysrc', None)
ffi.emit_python_code(str(tmpdir.join('re_python_pysrc.py')))
@@ -36,3 +41,20 @@
from re_python_pysrc import ffi
lib = ffi.dlopen(extmod)
assert lib.add42(-10) == 32
+
+def test_constant_via_lib():
+ from re_python_pysrc import ffi
+ lib = ffi.dlopen(extmod)
+ assert lib.FOOBAR == -42
+
+def test_opaque_struct():
+ from re_python_pysrc import ffi
+ ffi.cast("struct foo_s *", 0)
+ py.test.raises(TypeError, ffi.new, "struct foo_s *")
+
+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')
More information about the pypy-commit
mailing list