1
# Windows specific tests
4
from ctypes.test import is_resource_enabled
9
if sys.platform == "win32" and sizeof(c_void_p) == sizeof(c_int):
10
# Only windows 32-bit has different calling conventions.
12
class WindowsTestCase(unittest.TestCase):
13
def test_callconv_1(self):
14
# Testing stdcall function
16
IsWindow = windll.user32.IsWindow
17
# ValueError: Procedure probably called with not enough arguments (4 bytes missing)
18
self.assertRaises(ValueError, IsWindow)
20
# This one should succeeed...
21
self.failUnlessEqual(0, IsWindow(0))
23
# ValueError: Procedure probably called with too many arguments (8 bytes in excess)
24
self.assertRaises(ValueError, IsWindow, 0, 0, 0)
26
def test_callconv_2(self):
27
# Calling stdcall function as cdecl
29
IsWindow = cdll.user32.IsWindow
31
# ValueError: Procedure called with not enough arguments (4 bytes missing)
32
# or wrong calling convention
33
self.assertRaises(ValueError, IsWindow, None)
35
if sys.platform == "win32":
36
class FunctionCallTestCase(unittest.TestCase):
38
if is_resource_enabled("SEH"):
40
# Call functions with invalid arguments, and make sure
41
# that access violations are trapped and raise an
43
self.assertRaises(WindowsError, windll.kernel32.GetModuleHandleA, 32)
45
def test_noargs(self):
46
# This is a special case on win32 x64
47
windll.user32.GetDesktopWindow()
49
class TestWintypes(unittest.TestCase):
51
from ctypes import wintypes
52
self.failUnlessEqual(sizeof(wintypes.HWND), sizeof(c_void_p))
55
from ctypes import wintypes
56
self.failUnlessEqual(sizeof(wintypes.WPARAM),
58
self.failUnlessEqual(sizeof(wintypes.LPARAM),
61
def test_COMError(self):
62
from _ctypes import COMError
63
self.assertEqual(COMError.__doc__, "Raised when a COM method call failed.")
65
ex = COMError(-1, "text", ("details",))
66
self.assertEqual(ex.hresult, -1)
67
self.assertEqual(ex.text, "text")
68
self.assertEqual(ex.details, ("details",))
70
class Structures(unittest.TestCase):
72
def test_struct_by_value(self):
73
class POINT(Structure):
74
_fields_ = [("x", c_long),
77
class RECT(Structure):
78
_fields_ = [("left", c_long),
83
dll = CDLL(_ctypes_test.__file__)
86
rect = RECT(0, 0, 20, 20)
87
self.failUnlessEqual(1, dll.PointInRect(byref(rect), pt))
89
if __name__ == '__main__':