summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Leech <andrew@alelec.net>2016-09-13 10:12:53 +1000
committerAndrew Leech <andrew@alelec.net>2016-09-13 10:12:53 +1000
commit2e3754a50d9160847e92a688eb16f4da9cfbd3a5 (patch)
tree067ef94934a24fc19fb2b102295e7a41f6ce85b4
parent44f535d5e0e530f5054de55b1aca956b027e5519 (diff)
downloadcffi-2e3754a50d9160847e92a688eb16f4da9cfbd3a5.tar.gz
Add some initial test assertions to check length details on variable length structs
-rw-r--r--c/test_c.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/c/test_c.py b/c/test_c.py
index 867912c..60fcf42 100644
--- a/c/test_c.py
+++ b/c/test_c.py
@@ -3178,11 +3178,13 @@ def test_struct_array_no_length():
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 @@ def test_struct_array_no_length():
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 @@ def test_struct_array_no_length():
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")