Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(96255)

Side by Side Diff: Lib/ctypes/test/test_callbacks.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/ctypes/test/test_bitfields.py ('k') | Lib/ctypes/test/test_cfuncs.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os
1 import unittest 2 import unittest
2 from ctypes import * 3 from ctypes import *
3 from ctypes.test import need_symbol 4 from ctypes.test import need_symbol
4 import _ctypes_test 5 import _ctypes_test
5 6
6 class Callbacks(unittest.TestCase): 7 class Callbacks(unittest.TestCase):
7 functype = CFUNCTYPE 8 functype = CFUNCTYPE
8 9
9 ## def tearDown(self): 10 ## def tearDown(self):
10 ## import gc 11 ## import gc
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 functype = WINFUNCTYPE 151 functype = WINFUNCTYPE
151 except NameError: 152 except NameError:
152 pass 153 pass
153 154
154 ################################################################ 155 ################################################################
155 156
156 class SampleCallbacksTestCase(unittest.TestCase): 157 class SampleCallbacksTestCase(unittest.TestCase):
157 158
158 def test_integrate(self): 159 def test_integrate(self):
159 # Derived from some then non-working code, posted by David Foster 160 # Derived from some then non-working code, posted by David Foster
160 dll = CDLL(_ctypes_test.__file__) 161 dll = CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE ']))
161 162
162 # The function prototype called by 'integrate': double func(double); 163 # The function prototype called by 'integrate': double func(double);
163 CALLBACK = CFUNCTYPE(c_double, c_double) 164 CALLBACK = CFUNCTYPE(c_double, c_double)
164 165
165 # The integrate function itself, exposed from the _ctypes_test dll 166 # The integrate function itself, exposed from the _ctypes_test dll
166 integrate = dll.integrate 167 integrate = dll.integrate
167 integrate.argtypes = (c_double, c_double, CALLBACK, c_long) 168 integrate.argtypes = (c_double, c_double, CALLBACK, c_long)
168 integrate.restype = c_double 169 integrate.restype = c_double
169 170
170 def func(x): 171 def func(x):
(...skipping 30 matching lines...) Expand all
201 def EnumWindowsCallbackFunc(hwnd, lParam): 202 def EnumWindowsCallbackFunc(hwnd, lParam):
202 global windowCount 203 global windowCount
203 windowCount += 1 204 windowCount += 1
204 return True #Allow windows to keep enumerating 205 return True #Allow windows to keep enumerating
205 206
206 windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0) 207 windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0)
207 208
208 def test_callback_register_int(self): 209 def test_callback_register_int(self):
209 # Issue #8275: buggy handling of callback args under Win64 210 # Issue #8275: buggy handling of callback args under Win64
210 # NOTE: should be run on release builds as well 211 # NOTE: should be run on release builds as well
211 dll = CDLL(_ctypes_test.__file__) 212 dll = CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE ']))
212 CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_int, c_int, c_int) 213 CALLBACK = CFUNCTYPE(c_int, c_int, c_int, c_int, c_int, c_int)
213 # All this function does is call the callback with its args squared 214 # All this function does is call the callback with its args squared
214 func = dll._testfunc_cbk_reg_int 215 func = dll._testfunc_cbk_reg_int
215 func.argtypes = (c_int, c_int, c_int, c_int, c_int, CALLBACK) 216 func.argtypes = (c_int, c_int, c_int, c_int, c_int, CALLBACK)
216 func.restype = c_int 217 func.restype = c_int
217 218
218 def callback(a, b, c, d, e): 219 def callback(a, b, c, d, e):
219 return a + b + c + d + e 220 return a + b + c + d + e
220 221
221 result = func(2, 3, 4, 5, 6, CALLBACK(callback)) 222 result = func(2, 3, 4, 5, 6, CALLBACK(callback))
222 self.assertEqual(result, callback(2*2, 3*3, 4*4, 5*5, 6*6)) 223 self.assertEqual(result, callback(2*2, 3*3, 4*4, 5*5, 6*6))
223 224
224 def test_callback_register_double(self): 225 def test_callback_register_double(self):
225 # Issue #8275: buggy handling of callback args under Win64 226 # Issue #8275: buggy handling of callback args under Win64
226 # NOTE: should be run on release builds as well 227 # NOTE: should be run on release builds as well
227 dll = CDLL(_ctypes_test.__file__) 228 dll = CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE ']))
228 CALLBACK = CFUNCTYPE(c_double, c_double, c_double, c_double, 229 CALLBACK = CFUNCTYPE(c_double, c_double, c_double, c_double,
229 c_double, c_double) 230 c_double, c_double)
230 # All this function does is call the callback with its args squared 231 # All this function does is call the callback with its args squared
231 func = dll._testfunc_cbk_reg_double 232 func = dll._testfunc_cbk_reg_double
232 func.argtypes = (c_double, c_double, c_double, 233 func.argtypes = (c_double, c_double, c_double,
233 c_double, c_double, CALLBACK) 234 c_double, c_double, CALLBACK)
234 func.restype = c_double 235 func.restype = c_double
235 236
236 def callback(a, b, c, d, e): 237 def callback(a, b, c, d, e):
237 return a + b + c + d + e 238 return a + b + c + d + e
238 239
239 result = func(1.1, 2.2, 3.3, 4.4, 5.5, CALLBACK(callback)) 240 result = func(1.1, 2.2, 3.3, 4.4, 5.5, CALLBACK(callback))
240 self.assertEqual(result, 241 self.assertEqual(result,
241 callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5)) 242 callback(1.1*1.1, 2.2*2.2, 3.3*3.3, 4.4*4.4, 5.5*5.5))
242 243
243 244
244 ################################################################ 245 ################################################################
245 246
246 if __name__ == '__main__': 247 if __name__ == '__main__':
247 unittest.main() 248 unittest.main()
OLDNEW
« no previous file with comments | « Lib/ctypes/test/test_bitfields.py ('k') | Lib/ctypes/test/test_cfuncs.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+