Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
ctypes.test.test_parameters.SimpleTypesTestCase Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_subclasses
def test_cstrings
def test_cw_strings

Public Attributes

 prev_conv_mode

Detailed Description

Definition at line 3 of file test_parameters.py.


Member Function Documentation

Definition at line 5 of file test_parameters.py.

00005 
00006     def setUp(self):
00007         import ctypes
00008         try:
00009             from _ctypes import set_conversion_mode
00010         except ImportError:
00011             pass
00012         else:
00013             self.prev_conv_mode = set_conversion_mode("ascii", "strict")

Here is the caller graph for this function:

Definition at line 14 of file test_parameters.py.

00014 
00015     def tearDown(self):
00016         try:
00017             from _ctypes import set_conversion_mode
00018         except ImportError:
00019             pass
00020         else:
00021             set_conversion_mode(*self.prev_conv_mode)

Here is the caller graph for this function:

Definition at line 51 of file test_parameters.py.

00051 
00052     def test_cstrings(self):
00053         from ctypes import c_char_p, byref
00054 
00055         # c_char_p.from_param on a Python String packs the string
00056         # into a cparam object
00057         s = b"123"
00058         self.assertTrue(c_char_p.from_param(s)._obj is s)
00059 
00060         # new in 0.9.1: convert (encode) unicode to ascii
00061         self.assertEqual(c_char_p.from_param(b"123")._obj, b"123")
00062         self.assertRaises(TypeError, c_char_p.from_param, "123\377")
00063         self.assertRaises(TypeError, c_char_p.from_param, 42)
00064 
00065         # calling c_char_p.from_param with a c_char_p instance
00066         # returns the argument itself:
00067         a = c_char_p(b"123")
00068         self.assertTrue(c_char_p.from_param(a) is a)

Here is the call graph for this function:

Definition at line 69 of file test_parameters.py.

00069 
00070     def test_cw_strings(self):
00071         from ctypes import byref
00072         try:
00073             from ctypes import c_wchar_p
        except ImportError:

Definition at line 22 of file test_parameters.py.

00022 
00023     def test_subclasses(self):
00024         from ctypes import c_void_p, c_char_p
00025         # ctypes 0.9.5 and before did overwrite from_param in SimpleType_new
00026         class CVOIDP(c_void_p):
00027             def from_param(cls, value):
00028                 return value * 2
00029             from_param = classmethod(from_param)
00030 
00031         class CCHARP(c_char_p):
00032             def from_param(cls, value):
00033                 return value * 4
00034             from_param = classmethod(from_param)
00035 
00036         self.assertEqual(CVOIDP.from_param("abc"), "abcabc")
00037         self.assertEqual(CCHARP.from_param("abc"), "abcabcabcabc")
00038 
00039         try:
00040             from ctypes import c_wchar_p
00041         except ImportError:
00042             return
00043 
00044         class CWCHARP(c_wchar_p):
00045             def from_param(cls, value):
00046                 return value * 3
00047             from_param = classmethod(from_param)
00048 
00049         self.assertEqual(CWCHARP.from_param("abc"), "abcabcabc")

Here is the call graph for this function:


Member Data Documentation

Definition at line 12 of file test_parameters.py.


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