mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
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. ........
This commit is contained in:
parent
31b16a51fd
commit
b00697e67c
16 changed files with 1996 additions and 386 deletions
|
|
@ -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__':
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue