summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAntonin ENFRUN <antonin.e@me.com>2015-12-27 20:15:00 +0100
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-01-03 20:32:51 +0200
commitb50030b1d0eb3ae44d035bcde06fa213c30347ba (patch)
treebfe1c01e9463077ee02c89b44e30453a370b5ed0
parent26ed00118b48ccf9fca1308015e269f1fc400a79 (diff)
downloadmicropython-b50030b1d0eb3ae44d035bcde06fa213c30347ba.tar.gz
micropython-b50030b1d0eb3ae44d035bcde06fa213c30347ba.zip
tests/uctypes: Test item assignment for scalar arrays.
-rw-r--r--tests/extmod/uctypes_array_assign_le.py54
-rw-r--r--tests/extmod/uctypes_array_assign_le.py.exp7
-rw-r--r--tests/extmod/uctypes_array_assign_native_le.py46
-rw-r--r--tests/extmod/uctypes_array_assign_native_le.py.exp5
4 files changed, 112 insertions, 0 deletions
diff --git a/tests/extmod/uctypes_array_assign_le.py b/tests/extmod/uctypes_array_assign_le.py
new file mode 100644
index 0000000000..18d63f8bf9
--- /dev/null
+++ b/tests/extmod/uctypes_array_assign_le.py
@@ -0,0 +1,54 @@
+import uctypes
+
+desc = {
+ # arr is array at offset 0, of UINT8 elements, array size is 2
+ "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
+ # arr2 is array at offset 0, size 2, of structures defined recursively
+ "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
+ "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
+
+ # aligned
+ "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
+ # unaligned
+ "arr6": (uctypes.ARRAY | 1, uctypes.UINT32 | 1),
+
+ "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
+ "arr8": (uctypes.ARRAY | 1, 1, {"l": uctypes.UINT32 | 0})
+}
+
+data = bytearray(5)
+
+S = uctypes.struct(uctypes.addressof(data), desc, uctypes.LITTLE_ENDIAN)
+
+# assign byte
+S.arr[0] = 0x11
+print(hex(S.arr[0]))
+assert hex(S.arr[0]) == "0x11"
+
+# assign word
+S.arr3[0] = 0x2233
+print(hex(S.arr3[0]))
+assert hex(S.arr3[0]) == "0x2233"
+
+# assign word, with index
+S.arr3[1] = 0x4455
+print(hex(S.arr3[1]))
+assert hex(S.arr3[1]) == "0x4455"
+
+# assign long, aligned
+S.arr5[0] = 0x66778899
+print(hex(S.arr5[0]))
+assert hex(S.arr5[0]) == "0x66778899"
+
+print(S.arr5[0] == S.arr7[0].l)
+assert S.arr5[0] == S.arr7[0].l
+
+
+# assign long, unaligned
+S.arr6[0] = 0xAABBCCDD
+print(hex(S.arr6[0]))
+assert hex(S.arr6[0]) == "0xaabbccdd"
+
+print(S.arr6[0] == S.arr8[0].l)
+assert S.arr6[0] == S.arr8[0].l
+
diff --git a/tests/extmod/uctypes_array_assign_le.py.exp b/tests/extmod/uctypes_array_assign_le.py.exp
new file mode 100644
index 0000000000..8d57bc8ab0
--- /dev/null
+++ b/tests/extmod/uctypes_array_assign_le.py.exp
@@ -0,0 +1,7 @@
+0x11
+0x2233
+0x4455
+0x66778899
+True
+0xaabbccdd
+True
diff --git a/tests/extmod/uctypes_array_assign_native_le.py b/tests/extmod/uctypes_array_assign_native_le.py
new file mode 100644
index 0000000000..6901654dd8
--- /dev/null
+++ b/tests/extmod/uctypes_array_assign_native_le.py
@@ -0,0 +1,46 @@
+import sys
+import uctypes
+
+if sys.byteorder != "little":
+ print("SKIP")
+ sys.exit()
+
+desc = {
+ # arr is array at offset 0, of UINT8 elements, array size is 2
+ "arr": (uctypes.ARRAY | 0, uctypes.UINT8 | 2),
+ # arr2 is array at offset 0, size 2, of structures defined recursively
+ "arr2": (uctypes.ARRAY | 0, 2, {"b": uctypes.UINT8 | 0}),
+ "arr3": (uctypes.ARRAY | 2, uctypes.UINT16 | 2),
+
+ # aligned
+ "arr5": (uctypes.ARRAY | 0, uctypes.UINT32 | 1),
+ "arr7": (uctypes.ARRAY | 0, 1, {"l": uctypes.UINT32 | 0}),
+}
+
+data = bytearray(5)
+
+S = uctypes.struct(uctypes.addressof(data), desc)
+
+# assign byte
+S.arr[0] = 0x11
+print(hex(S.arr[0]))
+assert hex(S.arr[0]) == "0x11"
+
+# assign word
+S.arr3[0] = 0x2233
+print(hex(S.arr3[0]))
+assert hex(S.arr3[0]) == "0x2233"
+
+# assign word, with index
+S.arr3[1] = 0x4455
+print(hex(S.arr3[1]))
+assert hex(S.arr3[1]) == "0x4455"
+
+# assign long, aligned
+S.arr5[0] = 0x66778899
+print(hex(S.arr5[0]))
+assert hex(S.arr5[0]) == "0x66778899"
+
+print(S.arr5[0] == S.arr7[0].l)
+assert S.arr5[0] == S.arr7[0].l
+
diff --git a/tests/extmod/uctypes_array_assign_native_le.py.exp b/tests/extmod/uctypes_array_assign_native_le.py.exp
new file mode 100644
index 0000000000..0c3dc50fb0
--- /dev/null
+++ b/tests/extmod/uctypes_array_assign_native_le.py.exp
@@ -0,0 +1,5 @@
+0x11
+0x2233
+0x4455
+0x66778899
+True