ยปCore Development>Code coverage>Lib/ctypes/test/test_unaligned_structures.py

Python code coverage for Lib/ctypes/test/test_unaligned_structures.py

#countcontent
1n/aimport sys, unittest
2n/afrom ctypes import *
3n/a
4n/astructures = []
5n/abyteswapped_structures = []
6n/a
7n/a
8n/aif sys.byteorder == "little":
9n/a SwappedStructure = BigEndianStructure
10n/aelse:
11n/a SwappedStructure = LittleEndianStructure
12n/a
13n/afor typ in [c_short, c_int, c_long, c_longlong,
14n/a c_float, c_double,
15n/a c_ushort, c_uint, c_ulong, c_ulonglong]:
16n/a class X(Structure):
17n/a _pack_ = 1
18n/a _fields_ = [("pad", c_byte),
19n/a ("value", typ)]
20n/a class Y(SwappedStructure):
21n/a _pack_ = 1
22n/a _fields_ = [("pad", c_byte),
23n/a ("value", typ)]
24n/a structures.append(X)
25n/a byteswapped_structures.append(Y)
26n/a
27n/aclass TestStructures(unittest.TestCase):
28n/a def test_native(self):
29n/a for typ in structures:
30n/a## print typ.value
31n/a self.assertEqual(typ.value.offset, 1)
32n/a o = typ()
33n/a o.value = 4
34n/a self.assertEqual(o.value, 4)
35n/a
36n/a def test_swapped(self):
37n/a for typ in byteswapped_structures:
38n/a## print >> sys.stderr, typ.value
39n/a self.assertEqual(typ.value.offset, 1)
40n/a o = typ()
41n/a o.value = 4
42n/a self.assertEqual(o.value, 4)
43n/a
44n/aif __name__ == '__main__':
45n/a unittest.main()