Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
b50030b1
Commit
b50030b1
authored
Dec 27, 2015
by
Antonin ENFRUN
Committed by
Paul Sokolovsky
Jan 03, 2016
Browse files
tests/uctypes: Test item assignment for scalar arrays.
parent
26ed0011
Changes
4
Hide whitespace changes
Inline
Side-by-side
tests/extmod/uctypes_array_assign_le.py
0 → 100644
View file @
b50030b1
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
tests/extmod/uctypes_array_assign_le.py.exp
0 → 100644
View file @
b50030b1
0x11
0x2233
0x4455
0x66778899
True
0xaabbccdd
True
tests/extmod/uctypes_array_assign_native_le.py
0 → 100644
View file @
b50030b1
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
tests/extmod/uctypes_array_assign_native_le.py.exp
0 → 100644
View file @
b50030b1
0x11
0x2233
0x4455
0x66778899
True
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment