Back to index

python3.2  3.2.2
Public Member Functions
ctypes.test.test_anon.AnonTest Class Reference

List of all members.

Public Member Functions

def test_anon
def test_anon_nonseq
def test_anon_nonmember
def test_nested

Detailed Description

Definition at line 4 of file test_anon.py.


Member Function Documentation

Definition at line 6 of file test_anon.py.

00006 
00007     def test_anon(self):
00008         class ANON(Union):
00009             _fields_ = [("a", c_int),
00010                         ("b", c_int)]
00011 
00012         class Y(Structure):
00013             _fields_ = [("x", c_int),
00014                         ("_", ANON),
00015                         ("y", c_int)]
00016             _anonymous_ = ["_"]
00017 
00018         self.assertEqual(Y.a.offset, sizeof(c_int))
00019         self.assertEqual(Y.b.offset, sizeof(c_int))
00020 
00021         self.assertEqual(ANON.a.offset, 0)
00022         self.assertEqual(ANON.b.offset, 0)

Here is the call graph for this function:

Definition at line 30 of file test_anon.py.

00030 
00031     def test_anon_nonmember(self):
00032         # AttributeError: type object 'Name' has no attribute 'x'
00033         self.assertRaises(AttributeError,
00034                               lambda: type(Structure)("Name",
00035                                                       (Structure,),
00036                                                       {"_fields_": [],
00037                                                        "_anonymous_": ["x"]}))

Here is the call graph for this function:

Definition at line 23 of file test_anon.py.

00023 
00024     def test_anon_nonseq(self):
00025         # TypeError: _anonymous_ must be a sequence
00026         self.assertRaises(TypeError,
00027                               lambda: type(Structure)("Name",
00028                                                       (Structure,),
00029                                                       {"_fields_": [], "_anonymous_": 42}))

Here is the call graph for this function:

Definition at line 38 of file test_anon.py.

00038 
00039     def test_nested(self):
00040         class ANON_S(Structure):
00041             _fields_ = [("a", c_int)]
00042 
00043         class ANON_U(Union):
00044             _fields_ = [("_", ANON_S),
00045                         ("b", c_int)]
00046             _anonymous_ = ["_"]
00047 
00048         class Y(Structure):
00049             _fields_ = [("x", c_int),
00050                         ("_", ANON_U),
00051                         ("y", c_int)]
00052             _anonymous_ = ["_"]
00053 
00054         self.assertEqual(Y.x.offset, 0)
00055         self.assertEqual(Y.a.offset, sizeof(c_int))
00056         self.assertEqual(Y.b.offset, sizeof(c_int))
00057         self.assertEqual(Y._.offset, sizeof(c_int))
00058         self.assertEqual(Y.y.offset, sizeof(c_int) * 2)

Here is the call graph for this function:


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