Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_returnfuncptrs.ReturnFuncPtrTestCase Class Reference

List of all members.

Public Member Functions

def test_with_prototype
def test_without_prototype

Detailed Description

Definition at line 6 of file test_returnfuncptrs.py.


Member Function Documentation

Definition at line 8 of file test_returnfuncptrs.py.

00008 
00009     def test_with_prototype(self):
00010         # The _ctypes_test shared lib/dll exports quite some functions for testing.
00011         # The get_strchr function returns a *pointer* to the C strchr function.
00012         dll = CDLL(_ctypes_test.__file__)
00013         get_strchr = dll.get_strchr
00014         get_strchr.restype = CFUNCTYPE(c_char_p, c_char_p, c_char)
00015         strchr = get_strchr()
00016         self.assertEqual(strchr(b"abcdef", b"b"), b"bcdef")
00017         self.assertEqual(strchr(b"abcdef", b"x"), None)
00018         self.assertEqual(strchr(b"abcdef", 98), b"bcdef")
00019         self.assertEqual(strchr(b"abcdef", 107), None)
00020         self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0)
00021         self.assertRaises(TypeError, strchr, b"abcdef")

Here is the call graph for this function:

Definition at line 22 of file test_returnfuncptrs.py.

00022 
00023     def test_without_prototype(self):
00024         dll = CDLL(_ctypes_test.__file__)
00025         get_strchr = dll.get_strchr
00026         # the default 'c_int' would not work on systems where sizeof(int) != sizeof(void *)
00027         get_strchr.restype = c_void_p
00028         addr = get_strchr()
00029         # _CFuncPtr instances are now callable with an integer argument
00030         # which denotes a function address:
00031         strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(addr)
00032         self.assertTrue(strchr(b"abcdef", b"b"), "bcdef")
00033         self.assertEqual(strchr(b"abcdef", b"x"), None)
00034         self.assertRaises(ArgumentError, strchr, b"abcdef", 3.0)
00035         self.assertRaises(TypeError, strchr, b"abcdef")

Here is the call graph for this function:


The documentation for this class was generated from the following file: