summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
Diffstat (limited to 'testing')
-rw-r--r--testing/cffi0/test_parsing.py32
-rw-r--r--testing/cffi1/test_commontypes.py15
-rw-r--r--testing/cffi1/test_ffi_obj.py14
-rw-r--r--testing/cffi1/test_parse_c_type.py7
-rw-r--r--testing/cffi1/test_verify1.py9
5 files changed, 39 insertions, 38 deletions
diff --git a/testing/cffi0/test_parsing.py b/testing/cffi0/test_parsing.py
index 4b10cc4..dea6126 100644
--- a/testing/cffi0/test_parsing.py
+++ b/testing/cffi0/test_parsing.py
@@ -286,38 +286,16 @@ def test_void_renamed_as_only_arg():
"typedef int (*func_t)(void_t);")
assert ffi.typeof("func_t").args == ()
-def test_win_common_types():
- from cffi.commontypes import COMMON_TYPES, _CACHE
- from cffi.commontypes import win_common_types, resolve_common_type
- #
- def clear_all(extra={}, old_dict=COMMON_TYPES.copy()):
- COMMON_TYPES.clear()
- COMMON_TYPES.update(old_dict)
- COMMON_TYPES.update(extra)
- _CACHE.clear()
- #
- for maxsize in [2**32-1, 2**64-1]:
- ct = win_common_types(maxsize)
- clear_all(ct)
- for key in sorted(ct):
- if ct[key] != 'set-unicode-needed':
- resolve_common_type(key)
- # assert did not crash
- # now try to use e.g. WPARAM (-> UINT_PTR -> unsigned 32/64-bit)
- for maxsize in [2**32-1, 2**64-1]:
- ct = win_common_types(maxsize)
- clear_all(ct)
- ffi = FFI()
- value = int(ffi.cast("WPARAM", -1))
- assert value == maxsize
- #
- clear_all()
-
def test_WPARAM_on_windows():
if sys.platform != 'win32':
py.test.skip("Only for Windows")
ffi = FFI()
ffi.cdef("void f(WPARAM);")
+ #
+ # WPARAM -> UINT_PTR -> unsigned 32/64-bit integer
+ ffi = FFI()
+ value = int(ffi.cast("WPARAM", -42))
+ assert value == sys.maxsize * 2 - 40
def test__is_constant_globalvar():
for input, expected_output in [
diff --git a/testing/cffi1/test_commontypes.py b/testing/cffi1/test_commontypes.py
new file mode 100644
index 0000000..212da8d
--- /dev/null
+++ b/testing/cffi1/test_commontypes.py
@@ -0,0 +1,15 @@
+import py, os, cffi
+import _cffi_backend
+
+
+def test_alphabetical_order():
+ f = open(os.path.join(os.path.dirname(cffi.__file__),
+ '..', 'c', 'commontypes.c'))
+ lines = [line for line in f.readlines() if line.strip().startswith('EQ(')]
+ f.close()
+ assert lines == sorted(lines)
+
+def test_get_common_types():
+ d = {}
+ _cffi_backend._get_common_types(d)
+ assert d["bool"] == "_Bool"
diff --git a/testing/cffi1/test_ffi_obj.py b/testing/cffi1/test_ffi_obj.py
index 8241c75..253206a 100644
--- a/testing/cffi1/test_ffi_obj.py
+++ b/testing/cffi1/test_ffi_obj.py
@@ -395,3 +395,17 @@ def test_ffi_new_allocator_4():
return ffi.NULL
alloc5 = ffi.new_allocator(myalloc5)
py.test.raises(MemoryError, alloc5, "int[5]")
+
+def test_bool_issue228():
+ ffi = _cffi1_backend.FFI()
+ fntype = ffi.typeof("int(*callback)(bool is_valid)")
+ assert repr(fntype.args[0]) == "<ctype '_Bool'>"
+
+def test_cast_from_int_type_to_bool():
+ ffi = _cffi1_backend.FFI()
+ for basetype in ['char', 'short', 'int', 'long', 'long long']:
+ for sign in ['signed', 'unsigned']:
+ type = '%s %s' % (sign, basetype)
+ assert int(ffi.cast("_Bool", ffi.cast(type, 42))) == 1
+ assert int(ffi.cast("bool", ffi.cast(type, 42))) == 1
+ assert int(ffi.cast("_Bool", ffi.cast(type, 0))) == 0
diff --git a/testing/cffi1/test_parse_c_type.py b/testing/cffi1/test_parse_c_type.py
index 479e0e8..e90243d 100644
--- a/testing/cffi1/test_parse_c_type.py
+++ b/testing/cffi1/test_parse_c_type.py
@@ -19,8 +19,11 @@ ffi = cffi.FFI()
ffi.cdef(header)
lib = ffi.verify(
- open(os.path.join(cffi_dir, '..', 'c', 'parse_c_type.c')).read(),
- include_dirs=[cffi_dir])
+ open(os.path.join(cffi_dir, '..', 'c', 'parse_c_type.c')).read() + """
+static const char *get_common_type(const char *search, size_t search_len) {
+ return NULL;
+}
+""", include_dirs=[cffi_dir])
class ParseError(Exception):
pass
diff --git a/testing/cffi1/test_verify1.py b/testing/cffi1/test_verify1.py
index ffc2fc3..4678736 100644
--- a/testing/cffi1/test_verify1.py
+++ b/testing/cffi1/test_verify1.py
@@ -1494,15 +1494,6 @@ def test_cannot_pass_float():
assert lib.foo(0) == 1
py.test.raises(TypeError, lib.foo, 0.0)
-def test_cast_from_int_type_to_bool():
- ffi = FFI()
- for basetype in ['char', 'short', 'int', 'long', 'long long']:
- for sign in ['signed', 'unsigned']:
- type = '%s %s' % (sign, basetype)
- assert int(ffi.cast("_Bool", ffi.cast(type, 42))) == 1
- assert int(ffi.cast("bool", ffi.cast(type, 42))) == 1
- assert int(ffi.cast("_Bool", ffi.cast(type, 0))) == 0
-
def test_addressof():
ffi = FFI()
ffi.cdef("""