Back to index

python3.2  3.2.2
test_checkretval.py
Go to the documentation of this file.
00001 import unittest
00002 
00003 from ctypes import *
00004 
00005 class CHECKED(c_int):
00006     def _check_retval_(value):
00007         # Receives a CHECKED instance.
00008         return str(value.value)
00009     _check_retval_ = staticmethod(_check_retval_)
00010 
00011 class Test(unittest.TestCase):
00012 
00013     def test_checkretval(self):
00014 
00015         import _ctypes_test
00016         dll = CDLL(_ctypes_test.__file__)
00017         self.assertEqual(42, dll._testfunc_p_p(42))
00018 
00019         dll._testfunc_p_p.restype = CHECKED
00020         self.assertEqual("42", dll._testfunc_p_p(42))
00021 
00022         dll._testfunc_p_p.restype = None
00023         self.assertEqual(None, dll._testfunc_p_p(42))
00024 
00025         del dll._testfunc_p_p.restype
00026         self.assertEqual(42, dll._testfunc_p_p(42))
00027 
00028     try:
00029         oledll
00030     except NameError:
00031         pass
00032     else:
00033         def test_oledll(self):
00034             self.assertRaises(WindowsError,
00035                                   oledll.oleaut32.CreateTypeLib2,
00036                                   0, None, None)
00037 
00038 if __name__ == "__main__":
00039     unittest.main()