circuitpython/tests/extmod/uctypes_sizeof_native.py

42 lines
1.0 KiB
Python
Raw Normal View History

2017-02-14 17:56:22 -05:00
try:
import uctypes
except ImportError:
print("SKIP")
raise SystemExit
S1 = {}
assert uctypes.sizeof(S1) == 0
S2 = {"a": uctypes.UINT8 | 0}
assert uctypes.sizeof(S2) == 1
2021-03-15 09:57:36 -04:00
S3 = {"a": uctypes.UINT8 | 0, "b": uctypes.UINT8 | 1}
assert uctypes.sizeof(S3) == 2
2021-03-15 09:57:36 -04:00
S4 = {"a": uctypes.UINT8 | 0, "b": uctypes.UINT32 | 4, "c": uctypes.UINT8 | 8}
assert uctypes.sizeof(S4) == 12
S5 = {
"a": uctypes.UINT8 | 0,
"b": uctypes.UINT32 | 4,
"c": uctypes.UINT8 | 8,
"d": uctypes.UINT32 | 0,
2021-03-15 09:57:36 -04:00
"sub": (4, {"b0": uctypes.UINT8 | 0, "b1": uctypes.UINT8 | 1}),
}
assert uctypes.sizeof(S5) == 12
s5 = uctypes.struct(0, S5)
assert uctypes.sizeof(s5) == 12
assert uctypes.sizeof(s5.sub) == 2
2021-03-15 09:57:36 -04:00
S6 = {"ptr": (uctypes.PTR | 0, uctypes.UINT8)}
# As if there're no other arch bitnesses
assert uctypes.sizeof(S6) in (4, 8)
2021-03-15 09:57:36 -04:00
S7 = {"arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 5)}
assert uctypes.sizeof(S7) == 5
2021-03-15 09:57:36 -04:00
S8 = {"arr": (uctypes.ARRAY | 0, 3, {"a": uctypes.UINT32 | 0, "b": uctypes.UINT8 | 4})}
assert uctypes.sizeof(S8) == 24