File: test_checkretval.py

package info (click to toggle)
python2.6 2.6.8-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 65,740 kB
  • sloc: ansic: 389,342; python: 376,882; asm: 9,734; sh: 4,934; makefile: 4,040; lisp: 2,933; objc: 775; xml: 62
file content (39 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import unittest

from ctypes import *

class CHECKED(c_int):
    def _check_retval_(value):
        # Receives a CHECKED instance.
        return str(value.value)
    _check_retval_ = staticmethod(_check_retval_)

class Test(unittest.TestCase):

    def test_checkretval(self):

        import _ctypes_test
        dll = CDLL(_ctypes_test.__file__)
        self.failUnlessEqual(42, dll._testfunc_p_p(42))

        dll._testfunc_p_p.restype = CHECKED
        self.failUnlessEqual("42", dll._testfunc_p_p(42))

        dll._testfunc_p_p.restype = None
        self.failUnlessEqual(None, dll._testfunc_p_p(42))

        del dll._testfunc_p_p.restype
        self.failUnlessEqual(42, dll._testfunc_p_p(42))

    try:
        oledll
    except NameError:
        pass
    else:
        def test_oledll(self):
            self.failUnlessRaises(WindowsError,
                                  oledll.oleaut32.CreateTypeLib2,
                                  0, None, None)

if __name__ == "__main__":
    unittest.main()