1 import unittest 2 3 from ctypes import * 4 from ctypes.test import need_symbol 5 6 class CHECKED(c_int): 7 def _check_retval_(value): 8 # Receives a CHECKED instance. 9 return str(value.value) 10 _check_retval_ = staticmethod(_check_retval_) 11 12 class Test(unittest.TestCase): 13 14 def test_checkretval(self): 15 16 import _ctypes_test 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 @need_symbol('oledll') 30 def test_oledll(self): 31 self.assertRaises(WindowsError, 32 oledll.oleaut32.CreateTypeLib2, 33 0, None, None) 34 35 if __name__ == "__main__": 36 unittest.main() 37