Home | History | Annotate | Download | only in test
      1 import unittest
      2 
      3 from ctypes import *
      4 
      5 class CHECKED(c_int):
      6     def _check_retval_(value):
      7         # Receives a CHECKED instance.
      8         return str(value.value)
      9     _check_retval_ = staticmethod(_check_retval_)
     10 
     11 class Test(unittest.TestCase):
     12 
     13     def test_checkretval(self):
     14 
     15         import _ctypes_test
     16         dll = CDLL(_ctypes_test.__file__)
     17         self.assertEqual(42, dll._testfunc_p_p(42))
     18 
     19         dll._testfunc_p_p.restype = CHECKED
     20         self.assertEqual("42", dll._testfunc_p_p(42))
     21 
     22         dll._testfunc_p_p.restype = None
     23         self.assertEqual(None, dll._testfunc_p_p(42))
     24 
     25         del dll._testfunc_p_p.restype
     26         self.assertEqual(42, dll._testfunc_p_p(42))
     27 
     28     try:
     29         oledll
     30     except NameError:
     31         pass
     32     else:
     33         def test_oledll(self):
     34             self.assertRaises(WindowsError,
     35                                   oledll.oleaut32.CreateTypeLib2,
     36                                   0, None, None)
     37 
     38 if __name__ == "__main__":
     39     unittest.main()
     40