diff options
author | Thomas Heller <theller@ctypes.org> | 2010-06-21 16:00:31 (GMT) |
---|---|---|
committer | Thomas Heller <theller@ctypes.org> | 2010-06-21 16:00:31 (GMT) |
commit | b00697e67c186cdcbc7fcb0f96d4d3304bdff7fa (patch) | |
tree | 7a3361c0a6d20910fb5f54feeba9ef816086e744 /Lib | |
parent | 31b16a51fd9d0a66ecae98ff9499019c106f6265 (diff) | |
download | cpython-b00697e67c186cdcbc7fcb0f96d4d3304bdff7fa.zip cpython-b00697e67c186cdcbc7fcb0f96d4d3304bdff7fa.tar.gz cpython-b00697e67c186cdcbc7fcb0f96d4d3304bdff7fa.tar.bz2 |
Merged revisions 82126-82127 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r82126 | thomas.heller | 2010-06-21 16:00:24 +0200 (Mo, 21 Jun 2010) | 1 line
Fix #8959 by reverting revision 80761.
........
r82127 | thomas.heller | 2010-06-21 17:01:18 +0200 (Mo, 21 Jun 2010) | 2 lines
Add tests for problems reported in issue 8959.
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/test/test_callbacks.py | 35 | ||||
-rw-r--r-- | Lib/ctypes/test/test_win32.py | 26 |
2 files changed, 61 insertions, 0 deletions
diff --git a/Lib/ctypes/test/test_callbacks.py b/Lib/ctypes/test/test_callbacks.py index 1466f26..ea51c33 100644 --- a/Lib/ctypes/test/test_callbacks.py +++ b/Lib/ctypes/test/test_callbacks.py @@ -166,6 +166,41 @@ class SampleCallbacksTestCase(unittest.TestCase): self.assertTrue(diff < 0.01, "%s not less than 0.01" % diff) + def test_issue_8959_a(self): + from ctypes.util import find_library + libc_path = find_library("c") + if not libc_path: + return # cannot test + libc = CDLL(libc_path) + + @CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int)) + def cmp_func(a, b): + return a[0] - b[0] + + array = (c_int * 5)(5, 1, 99, 7, 33) + + libc.qsort(array, len(array), sizeof(c_int), cmp_func) + self.assertEqual(array[:], [1, 5, 7, 33, 99]) + + try: + WINFUNCTYPE + except NameError: + pass + else: + def test_issue_8959_b(self): + from ctypes.wintypes import BOOL, HWND, LPARAM + global windowCount + windowCount = 0 + + @WINFUNCTYPE(BOOL, HWND, LPARAM) + def EnumWindowsCallbackFunc(hwnd, lParam): + global windowCount + windowCount += 1 + return True #Allow windows to keep enumerating + + windll.user32.EnumWindows(EnumWindowsCallbackFunc, 0) + self.assertFalse(windowCount == 0) + ################################################################ if __name__ == '__main__': diff --git a/Lib/ctypes/test/test_win32.py b/Lib/ctypes/test/test_win32.py index 3c0500d..5dedd9f 100644 --- a/Lib/ctypes/test/test_win32.py +++ b/Lib/ctypes/test/test_win32.py @@ -6,6 +6,32 @@ import unittest, sys import _ctypes_test +if sys.platform == "win32" and sizeof(c_void_p) == sizeof(c_int): + # Only windows 32-bit has different calling conventions. + + class WindowsTestCase(unittest.TestCase): + def test_callconv_1(self): + # Testing stdcall function + + IsWindow = windll.user32.IsWindow + # ValueError: Procedure probably called with not enough arguments (4 bytes missing) + self.assertRaises(ValueError, IsWindow) + + # This one should succeeed... + self.assertEqual(0, IsWindow(0)) + + # ValueError: Procedure probably called with too many arguments (8 bytes in excess) + self.assertRaises(ValueError, IsWindow, 0, 0, 0) + + def test_callconv_2(self): + # Calling stdcall function as cdecl + + IsWindow = cdll.user32.IsWindow + + # ValueError: Procedure called with not enough arguments (4 bytes missing) + # or wrong calling convention + self.assertRaises(ValueError, IsWindow, None) + if sys.platform == "win32": class FunctionCallTestCase(unittest.TestCase): |