6
class ReturnFuncPtrTestCase(unittest.TestCase):
8
def test_with_prototype(self):
9
# The _ctypes_test shared lib/dll exports quite some functions for testing.
10
# The get_strchr function returns a *pointer* to the C strchr function.
11
dll = CDLL(_ctypes_test.__file__)
12
get_strchr = dll.get_strchr
13
get_strchr.restype = CFUNCTYPE(c_char_p, c_char_p, c_char)
15
self.failUnlessEqual(strchr("abcdef", "b"), "bcdef")
16
self.failUnlessEqual(strchr("abcdef", "x"), None)
17
self.assertRaises(ArgumentError, strchr, "abcdef", 3)
18
self.assertRaises(TypeError, strchr, "abcdef")
20
def test_without_prototype(self):
21
dll = CDLL(_ctypes_test.__file__)
22
get_strchr = dll.get_strchr
23
# the default 'c_int' would not work on systems where sizeof(int) != sizeof(void *)
24
get_strchr.restype = c_void_p
26
# _CFuncPtr instances are now callable with an integer argument
27
# which denotes a function address:
28
strchr = CFUNCTYPE(c_char_p, c_char_p, c_char)(addr)
29
self.failUnless(strchr("abcdef", "b"), "bcdef")
30
self.failUnlessEqual(strchr("abcdef", "x"), None)
31
self.assertRaises(ArgumentError, strchr, "abcdef", 3)
32
self.assertRaises(TypeError, strchr, "abcdef")
34
if __name__ == "__main__":