diff options
author | Armin Rigo <arigo@tunes.org> | 2015-10-06 10:37:00 +0200 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2015-10-06 10:37:00 +0200 |
commit | ff1d14e325067c03a26020dc90900319a52513a3 (patch) | |
tree | 0882885ee6a424f6aa905f82baae464872d3f37e /testing/cffi0 | |
parent | 7ef565fb0fe6167ba278ad4ca551f7e8441b4599 (diff) | |
download | cffi-ff1d14e325067c03a26020dc90900319a52513a3.tar.gz |
start to fix tests
Diffstat (limited to 'testing/cffi0')
-rw-r--r-- | testing/cffi0/test_function.py | 24 | ||||
-rw-r--r-- | testing/cffi0/test_verify.py | 30 |
2 files changed, 27 insertions, 27 deletions
diff --git a/testing/cffi0/test_function.py b/testing/cffi0/test_function.py index 1dcf6d5..1a2995d 100644 --- a/testing/cffi0/test_function.py +++ b/testing/cffi0/test_function.py @@ -444,24 +444,24 @@ class TestFunction(object): # ffi = FFI(backend=self.Backend()) ffi.cdef(""" - BOOL QueryPerformanceFrequency(LONGLONG *lpFrequency); - """, calling_conv="cdecl") + BOOL __cdecl QueryPerformanceFrequency(LONGLONG *lpFrequency); + """) m = ffi.dlopen("Kernel32.dll") tpc = ffi.typeof(m.QueryPerformanceFrequency) assert tpc is tp # ffi = FFI(backend=self.Backend()) ffi.cdef(""" - BOOL QueryPerformanceFrequency(LONGLONG *lpFrequency); - """, calling_conv="stdcall") + BOOL WINAPI QueryPerformanceFrequency(LONGLONG *lpFrequency); + """) m = ffi.dlopen("Kernel32.dll") tps = ffi.typeof(m.QueryPerformanceFrequency) assert tps is not tpc assert str(tps) == "<ctype 'int(__stdcall *)(long long *)'>" # ffi = FFI(backend=self.Backend()) - ffi.cdef("typedef int (*fnc_t)(int);", calling_conv="cdecl") - ffi.cdef("typedef int (*fns_t)(int);", calling_conv="stdcall") + ffi.cdef("typedef int (__cdecl *fnc_t)(int);") + ffi.cdef("typedef int (__stdcall *fns_t)(int);") tpc = ffi.typeof("fnc_t") tps = ffi.typeof("fns_t") assert str(tpc) == "<ctype 'int(*)(int)'>" @@ -478,10 +478,8 @@ class TestFunction(object): if sys.platform == 'win32': py.test.skip("not-Windows-only test") ffi = FFI(backend=self.Backend()) - ffi.cdef(""" - int QueryPerformanceFrequency(long long *lpFrequency); - """, calling_conv="stdcall") - m = ffi.dlopen(None) - e = py.test.raises(CDefError, getattr, m, 'QueryPerformanceFrequency') - assert str(e.value) == ( - "<int(__stdcall *)(long long *)>: '__stdcall' only for Windows") + ffi.cdef("double __stdcall sin(double x);") # stdcall ignored + m = ffi.dlopen(lib_m) + assert "double(*)(double)" in str(ffi.typeof(m.sin)) + x = m.sin(1.23) + assert x == math.sin(1.23) diff --git a/testing/cffi0/test_verify.py b/testing/cffi0/test_verify.py index bb76cec..fd84128 100644 --- a/testing/cffi0/test_verify.py +++ b/testing/cffi0/test_verify.py @@ -2246,9 +2246,16 @@ def test_win32_calling_convention_1(): if sys.platform != 'win32': py.test.skip("Windows only") ffi = FFI() - ffi.cdef("int call1(int(*cb)(int));", calling_conv="cdecl") - ffi.cdef("int call2(int(*cb)(int));", calling_conv="stdcall") + ffi.cdef(""" + int __cdecl call1(int(__cdecl *cb)(int)); + int __stdcall call2(int(__stdcall *cb)(int)); + int (__cdecl *const cb1)(int); + int (__stdcall *const cb2)(int); + """) lib = ffi.verify(r""" + int __cdecl cb1(int x) { return x * 2; } + int __stdcall cb2(int x) { return x * 3; } + int __cdecl call1(int(__cdecl *cb)(int)) { printf("here1\n"); printf("cb = %p, cb1 = %p\n", cb, (void *)cb1); @@ -2268,13 +2275,8 @@ def test_win32_calling_convention_1(): return result; } """) - assert lib.call1(ffi.addressof(lib, 'cb1')) == 500*999*2 - ... - print '<<< cb2 =', ffi.addressof(lib, 'cb2') - ptr_call2 = ffi.addressof(lib, 'call2') - assert lib.call2(ffi.addressof(lib, 'cb2')) == -500*999*3 - assert ptr_call2(ffi.addressof(lib, 'cb2')) == -500*999*3 - print '<<< done' + assert lib.call1(lib.cb1) == 500*999*2 + assert lib.call2(lib.cb2) == -500*999*3 def test_win32_calling_convention_2(): if sys.platform != 'win32': @@ -2284,16 +2286,16 @@ def test_win32_calling_convention_2(): # automatically corrected. But this does not apply to the 'cb' # function pointer argument. ffi = FFI() - ffi.cdef("int call1(int(*cb)(int)); int cb1(int);", calling_conv="cdecl") - ffi.cdef("int call2(int(*cb)(int)); int cb2(int);", calling_conv="stdcall") + ffi.cdef("int __stdcall call1(int(*cb)(int)); int cb1(int);") + ffi.cdef("int call2(int(__stdcall *cb)(int)); int __stdcall cb2(int);") lib = verify(ffi, 'test_win32_calling_convention_2', """ - int __stdcall call1(int(__cdecl *cb)(int)) { + int __cdecl call1(int(__cdecl *cb)(int)) { int i, result = 0; for (i = 0; i < 1000; i++) result += cb(i); return result; } - int __cdecl call2(int(__stdcall *cb)(int)) { + int __stdcall call2(int(__stdcall *cb)(int)) { int i, result = 0; for (i = 0; i < 1000; i++) result += cb(-i); @@ -2318,7 +2320,7 @@ def test_win32_calling_convention_3(): py.test.skip("Windows only") ffi = FFI() ffi.cdef("struct point { int x, y; };") - ffi.cdef("struct point call1(int(*cb)(struct point)); " + ffi.cdef("struct point __stdcall call1(int(*__cdecl cb)(struct point)); " "int cb1(struct point);", calling_conv="cdecl") ffi.cdef("struct point call2(int(*cb)(struct point)); " "int cb2(struct point);", calling_conv="stdcall") |