| 1 |
import pytest |
| 2 |
from ctypes import * |
| 3 |
|
| 4 |
unsigned_types = [c_ubyte, c_ushort, c_uint, c_ulong] |
| 5 |
signed_types = [c_byte, c_short, c_int, c_long, c_longlong] |
| 6 |
|
| 7 |
float_types = [c_double, c_float, c_longdouble] |
| 8 |
|
| 9 |
try: |
| 10 |
c_ulonglong |
| 11 |
c_longlong |
| 12 |
except NameError: |
| 13 |
pass |
| 14 |
else: |
| 15 |
unsigned_types.append(c_ulonglong) |
| 16 |
signed_types.append(c_longlong) |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
@pytest.mark.parametrize('t', signed_types + unsigned_types + float_types) |
| 21 |
def test_init_again(t): |
| 22 |
parm = t() |
| 23 |
addr1 = addressof(parm) |
| 24 |
parm.__init__(0) |
| 25 |
addr2 = addressof(parm) |
| 26 |
assert addr1 == addr2 |
| 27 |
|
| 28 |
def test_subclass(): |
| 29 |
class enum(c_int): |
| 30 |
def __new__(cls, value): |
| 31 |
dont_call_me |
| 32 |
class S(Structure): |
| 33 |
_fields_ = [('t', enum)] |
| 34 |
assert isinstance(S().t, enum) |
| 35 |
|
| 36 |
|
| 37 |
@pytest.mark.xfail |
| 38 |
def test_no_missing_shape_to_ffi_type(): |
| 39 |
|
| 40 |
"re-enable after adding 'g' to _shape_to_ffi_type.typemap, " |
| 41 |
"which I think needs fighting all the way up from " |
| 42 |
"rpython.rlib.libffi" |
| 43 |
from _ctypes.basics import _shape_to_ffi_type |
| 44 |
from _rawffi import Array |
| 45 |
for i in range(1, 256): |
| 46 |
try: |
| 47 |
Array(chr(i)) |
| 48 |
except ValueError: |
| 49 |
pass |
| 50 |
else: |
| 51 |
assert chr(i) in _shape_to_ffi_type.typemap |
| 52 |
|
| 53 |
@pytest.mark.xfail |
| 54 |
def test_pointer_to_long_double(): |
| 55 |
import ctypes |
| 56 |
ctypes.POINTER(ctypes.c_longdouble) |