[pypy-commit] cffi calculate_variable_array_length: Add some initial test assertions to check length details on variable length structs
coronafire
pypy.commits at gmail.com
Wed Oct 19 02:53:33 EDT 2016
Author: Andrew Leech <andrew at alelec.net>
Branch: calculate_variable_array_length
Changeset: r2790:f97bac9fc85c
Date: 2016-09-13 10:12 +1000
http://bitbucket.org/cffi/cffi/changeset/f97bac9fc85c/
Log: Add some initial test assertions to check length details on variable
length structs
diff --git a/c/test_c.py b/c/test_c.py
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -3178,11 +3178,13 @@
p = newp(new_pointer_type(BStruct))
p.x = 42
assert p.x == 42
- assert typeof(p.y) is BIntP
+ assert typeof(p.y) is BArray
+ assert len(p.y) == 0
assert p.y == cast(BIntP, p) + 1
#
p = newp(new_pointer_type(BStruct), [100])
assert p.x == 100
+ assert len(p.y) == 0
#
# Tests for
# ffi.new("struct_with_var_array *", [field.., [the_array_items..]])
@@ -3197,6 +3199,8 @@
p.y[0] = 200
assert p.y[2] == 0
p.y[2] = 400
+ assert len(p.y) == 3
+ assert len(buffer(p)) == sizeof(BInt) * 4
plist.append(p)
for i in range(20):
p = plist[i]
@@ -3204,13 +3208,14 @@
assert p.y[0] == 200
assert p.y[1] == i
assert p.y[2] == 400
- assert list(p.y[0:3]) == [200, i, 400]
+ assert list(p.y) == [200, i, 400]
#
# the following assignment works, as it normally would, for any array field
p.y = [500, 600]
- assert list(p.y[0:3]) == [500, 600, 400]
+ assert list(p.y) == [500, 600, 400]
#
# error cases
+ py.test.raises(IndexError, "p.y[4]")
py.test.raises(TypeError, "p.y = cast(BIntP, 0)")
py.test.raises(TypeError, "p.y = 15")
py.test.raises(TypeError, "p.y = None")
More information about the pypy-commit
mailing list