| 1 |
import ctypes |
| 2 |
import unittest |
| 3 |
from ctypes import CDLL, c_int |
| 4 |
from test.support import import_helper |
| 5 |
_ctypes_test = import_helper.import_module("_ctypes_test") |
| 6 |
|
| 7 |
|
| 8 |
class CHECKED(c_int): |
| 9 |
def _check_retval_(value): |
| 10 |
# Receives a CHECKED instance. |
| 11 |
return str(value.value) |
| 12 |
_check_retval_ = staticmethod(_check_retval_) |
| 13 |
|
| 14 |
|
| 15 |
class Test(unittest.TestCase): |
| 16 |
def test_checkretval(self): |
| 17 |
dll = CDLL(_ctypes_test.__file__) |
| 18 |
self.assertEqual(42, dll._testfunc_p_p(42)) |
| 19 |
|
| 20 |
dll._testfunc_p_p.restype = CHECKED |
| 21 |
self.assertEqual("42", dll._testfunc_p_p(42)) |
| 22 |
|
| 23 |
dll._testfunc_p_p.restype = None |
| 24 |
self.assertEqual(None, dll._testfunc_p_p(42)) |
| 25 |
|
| 26 |
del dll._testfunc_p_p.restype |
| 27 |
self.assertEqual(42, dll._testfunc_p_p(42)) |
| 28 |
|
| 29 |
@unittest.skipUnless(hasattr(ctypes, 'oledll'), |
| 30 |
'ctypes.oledll is required') |
| 31 |
def test_oledll(self): |
| 32 |
oleaut32 = ctypes.oledll.oleaut32 |
| 33 |
self.assertRaises(OSError, oleaut32.CreateTypeLib2, 0, None, None) |
| 34 |
|
| 35 |
|
| 36 |
if __name__ == "__main__": |
| 37 |
unittest.main() |