Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_prototypes.CharPointersTestCase Class Reference

List of all members.

Public Member Functions

def setUp
def test_paramflags
def test_int_pointer_arg
def test_POINTER_c_char_arg
def test_c_char_p_arg
def test_c_void_p_arg
def test_instance

Detailed Description

Definition at line 44 of file test_prototypes.py.


Member Function Documentation

Definition at line 46 of file test_prototypes.py.

00046 
00047     def setUp(self):
00048         func = testdll._testfunc_p_p
00049         func.restype = c_long
00050         func.argtypes = None

Here is the caller graph for this function:

Definition at line 104 of file test_prototypes.py.

00104 
00105     def test_c_char_p_arg(self):
00106         func = testdll._testfunc_p_p
00107         func.restype = c_char_p
00108         func.argtypes = c_char_p,
00109 
00110         self.assertEqual(None, func(None))
00111         self.assertEqual(b"123", func(b"123"))
00112         self.assertEqual(None, func(c_char_p(None)))
00113         self.assertEqual(b"123", func(c_char_p(b"123")))
00114 
00115         self.assertEqual(b"123", func(c_buffer(b"123")))
00116         ca = c_char(b"a")
00117         self.assertEqual(ord(b"a"), func(pointer(ca))[0])
00118         self.assertEqual(ord(b"a"), func(byref(ca))[0])

Here is the call graph for this function:

Definition at line 119 of file test_prototypes.py.

00119 
00120     def test_c_void_p_arg(self):
00121         func = testdll._testfunc_p_p
00122         func.restype = c_char_p
00123         func.argtypes = c_void_p,
00124 
00125         self.assertEqual(None, func(None))
00126         self.assertEqual(b"123", func(b"123"))
00127         self.assertEqual(b"123", func(c_char_p(b"123")))
00128         self.assertEqual(None, func(c_char_p(None)))
00129 
00130         self.assertEqual(b"123", func(c_buffer(b"123")))
00131         ca = c_char(b"a")
00132         self.assertEqual(ord(b"a"), func(pointer(ca))[0])
00133         self.assertEqual(ord(b"a"), func(byref(ca))[0])
00134 
00135         func(byref(c_int()))
00136         func(pointer(c_int()))
00137         func((c_int * 3)())
00138 
00139         try:
00140             func.restype = c_wchar_p
00141         except NameError:
00142             pass
00143         else:
00144             self.assertEqual(None, func(c_wchar_p(None)))
00145             self.assertEqual("123", func(c_wchar_p("123")))

Here is the call graph for this function:

Definition at line 146 of file test_prototypes.py.

00146 
00147     def test_instance(self):
00148         func = testdll._testfunc_p_p
00149         func.restype = c_void_p
00150 
00151         class X:
00152             _as_parameter_ = None
00153 
00154         func.argtypes = c_void_p,
00155         self.assertEqual(None, func(X()))
00156 
00157         func.argtypes = None
00158         self.assertEqual(None, func(X()))
00159 
try:

Here is the call graph for this function:

Definition at line 69 of file test_prototypes.py.

00069 
00070     def test_int_pointer_arg(self):
00071         func = testdll._testfunc_p_p
00072         func.restype = c_long
00073         self.assertEqual(0, func(0))
00074 
00075         ci = c_int(0)
00076 
00077         func.argtypes = POINTER(c_int),
00078         self.assertEqual(positive_address(addressof(ci)),
00079                              positive_address(func(byref(ci))))
00080 
00081         func.argtypes = c_char_p,
00082         self.assertRaises(ArgumentError, func, byref(ci))
00083 
00084         func.argtypes = POINTER(c_short),
00085         self.assertRaises(ArgumentError, func, byref(ci))
00086 
00087         func.argtypes = POINTER(c_double),
00088         self.assertRaises(ArgumentError, func, byref(ci))

Here is the call graph for this function:

Definition at line 51 of file test_prototypes.py.

00051 
00052     def test_paramflags(self):
00053         # function returns c_void_p result,
00054         # and has a required parameter named 'input'
00055         prototype = CFUNCTYPE(c_void_p, c_void_p)
00056         func = prototype(("_testfunc_p_p", testdll),
00057                          ((1, "input"),))
00058 
00059         try:
00060             func()
00061         except TypeError as details:
00062             self.assertEqual(str(details), "required argument 'input' missing")
00063         else:
00064             self.fail("TypeError not raised")
00065 
00066         self.assertEqual(func(None), None)
00067         self.assertEqual(func(input=None), None)
00068 

Here is the call graph for this function:

Definition at line 89 of file test_prototypes.py.

00089 
00090     def test_POINTER_c_char_arg(self):
00091         func = testdll._testfunc_p_p
00092         func.restype = c_char_p
00093         func.argtypes = POINTER(c_char),
00094 
00095         self.assertEqual(None, func(None))
00096         self.assertEqual(b"123", func(b"123"))
00097         self.assertEqual(None, func(c_char_p(None)))
00098         self.assertEqual(b"123", func(c_char_p(b"123")))
00099 
00100         self.assertEqual(b"123", func(c_buffer(b"123")))
00101         ca = c_char(b"a")
00102         self.assertEqual(ord(b"a"), func(pointer(ca))[0])
00103         self.assertEqual(ord(b"a"), func(byref(ca))[0])

Here is the call graph for this function:


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