[pypy-commit] pypy default: Copy the test from cffi/c/test_c

arigo noreply at buildbot.pypy.org
Mon Aug 27 22:11:42 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r56889:ad4ac20a30a2
Date: 2012-08-27 22:08 +0200
http://bitbucket.org/pypy/pypy/changeset/ad4ac20a30a2/

Log:	Copy the test from cffi/c/test_c

diff --git a/pypy/module/_cffi_backend/test/_backend_test_c.py b/pypy/module/_cffi_backend/test/_backend_test_c.py
--- a/pypy/module/_cffi_backend/test/_backend_test_c.py
+++ b/pypy/module/_cffi_backend/test/_backend_test_c.py
@@ -2035,3 +2035,21 @@
     assert d[2][1].offset == sizeof(BInt) * 2
     assert d[2][1].bitshift == -1
     assert d[2][1].bitsize == -1
+
+def test_sizeof_union():
+    # a union has the largest alignment of its members, and a total size
+    # that is the largest of its items *possibly further aligned* if
+    # another smaller item has a larger alignment...
+    BChar = new_primitive_type("char")
+    BShort = new_primitive_type("short")
+    assert sizeof(BShort) == alignof(BShort) == 2
+    BStruct = new_struct_type("foo")
+    complete_struct_or_union(BStruct, [('a1', BChar),
+                                       ('a2', BChar),
+                                       ('a3', BChar)])
+    assert sizeof(BStruct) == 3 and alignof(BStruct) == 1
+    BUnion = new_union_type("u")
+    complete_struct_or_union(BUnion, [('s', BStruct),
+                                      ('i', BShort)])
+    assert sizeof(BUnion) == 4
+    assert alignof(BUnion) == 2


More information about the pypy-commit mailing list