def test_bitfield(self):
# struct bitfield { int a:10, b:20, c:3; };
assert ffi.sizeof("struct bitfield") == 8
s = ffi.new("struct bitfield *")
s.a = 511
py.test.raises(OverflowError, "s.a = 512")
py.test.raises(OverflowError, "s[0].a = 512")
assert s.a == 511
s.a = -512
py.test.raises(OverflowError, "s.a = -513")
py.test.raises(OverflowError, "s[0].a = -513")
assert s.a == -512
s.c = 3
assert s.c == 3
py.test.raises(OverflowError, "s.c = 4")
py.test.raises(OverflowError, "s[0].c = 4")
s.c = -4
assert s.c == -4
评论列表
文章目录