Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_callbacks.SampleCallbacksTestCase Class Reference

List of all members.

Public Member Functions

def test_integrate
def test_issue_8959_a
def test_issue_8959_b
def test_callback_register_int
def test_callback_register_double

Detailed Description

Definition at line 147 of file test_callbacks.py.


Member Function Documentation

Definition at line 219 of file test_callbacks.py.

00219 
00220     def test_callback_register_double(self):
00221         # Issue #8275: buggy handling of callback args under Win64
00222         # NOTE: should be run on release builds as well
00223         dll = CDLL(_ctypes_test.__file__)
00224         CALLBACK = CFUNCTYPE(c_double, c_double, c_double, c_double,
00225                              c_double, c_double)
00226         # All this function does is call the callback with its args squared
00227         func = dll._testfunc_cbk_reg_double
00228         func.argtypes = (c_double, c_double, c_double,
00229                          c_double, c_double, CALLBACK)
00230         func.restype = c_double
00231 
00232         def callback(a, b, c, d, e):
00233             return a + b + c + d + e
00234 
00235         result = func(1.1, 2.2, 3.3, 4.4, 5.5, CALLBACK(callback))
00236         self.assertEqual(result,
00237                          callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5))
00238 

Here is the call graph for this function:

Definition at line 203 of file test_callbacks.py.

00203 
00204     def test_callback_register_int(self):
00205         # Issue #8275: buggy handling of callback args under Win64
00206         # NOTE: should be run on release builds as well
00207         dll = CDLL(_ctypes_test.__file__)
00208         CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_int, c_int, c_int)
00209         # All this function does is call the callback with its args squared
00210         func = dll._testfunc_cbk_reg_int
00211         func.argtypes = (c_int, c_int, c_int, c_int, c_int, CALLBACK)
00212         func.restype = c_int
00213 
00214         def callback(a, b, c, d, e):
00215             return a + b + c + d + e
00216 
00217         result = func(2, 3, 4, 5, 6, CALLBACK(callback))
00218         self.assertEqual(result, callback(2*2, 3*3, 4*4, 5*5, 6*6))

Here is the call graph for this function:

Definition at line 149 of file test_callbacks.py.

00149 
00150     def test_integrate(self):
00151         # Derived from some then non-working code, posted by David Foster
00152         dll = CDLL(_ctypes_test.__file__)
00153 
00154         # The function prototype called by 'integrate': double func(double);
00155         CALLBACK = CFUNCTYPE(c_double, c_double)
00156 
00157         # The integrate function itself, exposed from the _ctypes_test dll
00158         integrate = dll.integrate
00159         integrate.argtypes = (c_double, c_double, CALLBACK, c_long)
00160         integrate.restype = c_double
00161 
00162         def func(x):
00163             return x**2
00164 
00165         result = integrate(0.0, 1.0, CALLBACK(func), 10)
00166         diff = abs(result - 1./3.)
00167 
00168         self.assertLess(diff, 0.01, "%s not less than 0.01" % diff)

Here is the call graph for this function:

Definition at line 169 of file test_callbacks.py.

00169 
00170     def test_issue_8959_a(self):
00171         from ctypes.util import find_library
00172         libc_path = find_library("c")
00173         if not libc_path:
00174             return # cannot test
00175         libc = CDLL(libc_path)
00176 
00177         @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
00178         def cmp_func(a, b):
00179             return a[0] - b[0]
00180 
00181         array = (c_int * 5)(5, 1, 99, 7, 33)
00182 
00183         libc.qsort(array, len(array), sizeof(c_int), cmp_func)
00184         self.assertEqual(array[:], [1, 5, 7, 33, 99])

Here is the call graph for this function:

Definition at line 190 of file test_callbacks.py.

00190 
00191         def test_issue_8959_b(self):
00192             from ctypes.wintypes import BOOL, HWND, LPARAM
00193             global windowCount
00194             windowCount = 0
00195 
00196             @WINFUNCTYPE(BOOL, HWND, LPARAM)
00197             def EnumWindowsCallbackFunc(hwnd, lParam):
00198                 global windowCount
00199                 windowCount += 1
00200                 return True #Allow windows to keep enumerating
00201 
00202             windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)

Here is the call graph for this function:


The documentation for this class was generated from the following file: