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