[pypy-commit] cffi cffi-1.0: more tests from test_ffi_backend
arigo
noreply at buildbot.pypy.org
Sun Apr 26 11:23:29 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch: cffi-1.0
Changeset: r1839:e80b46e5fa79
Date: 2015-04-26 11:11 +0200
http://bitbucket.org/cffi/cffi/changeset/e80b46e5fa79/
Log: more tests from test_ffi_backend
diff --git a/_cffi1/test_new_ffi_1.py b/_cffi1/test_new_ffi_1.py
--- a/_cffi1/test_new_ffi_1.py
+++ b/_cffi1/test_new_ffi_1.py
@@ -54,6 +54,7 @@
typedef struct { int a; } unnamed_foo_t, *unnamed_foo_p;
struct nonpacked { char a; int b; };
struct array0 { int len; short data[0]; };
+ struct array_no_length { int x; int a[]; };
struct nested_anon {
struct { int a, b; };
@@ -1603,3 +1604,20 @@
assert ffi.from_handle(p) is o
assert ffi.from_handle(ffi.cast("char *", p)) is o
py.test.raises(RuntimeError, ffi.from_handle, ffi.NULL)
+
+ def test_struct_array_no_length(self):
+ # struct array_no_length { int x; int a[]; };
+ p = ffi.new("struct array_no_length *", [100, [200, 300, 400]])
+ assert p.x == 100
+ assert ffi.typeof(p.a) is ffi.typeof("int *") # no length available
+ assert p.a[0] == 200
+ assert p.a[1] == 300
+ assert p.a[2] == 400
+
+ def test_from_buffer(self):
+ import array
+ a = array.array('H', [10000, 20000, 30000])
+ c = ffi.from_buffer(a)
+ assert ffi.typeof(c) is ffi.typeof("char[]")
+ ffi.cast("unsigned short *", c)[1] += 500
+ assert list(a) == [10000, 20500, 30000]
More information about the pypy-commit
mailing list