Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
cython
Commits
ee0cf002
Commit
ee0cf002
authored
Apr 02, 2011
by
Pauli Virtanen
Committed by
Dag Sverre Seljebotn
Apr 16, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TST: buffer: add additional buffer access tests for packed structs related to 3f599a8c
parent
56b88ec4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
tests/run/bufaccess.pyx
tests/run/bufaccess.pyx
+59
-0
No files found.
tests/run/bufaccess.pyx
View file @
ee0cf002
...
...
@@ -1281,6 +1281,16 @@ cdef struct NestedStruct:
SmallStruct
y
int
z
cdef
packed
struct
PackedStruct
:
char
a
int
b
cdef
struct
NestedPackedStruct
:
char
a
int
b
PackedStruct
sub
int
c
cdef
class
MyStructMockBuffer
(
MockBuffer
):
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
cdef
MyStruct
*
s
...
...
@@ -1301,6 +1311,26 @@ cdef class NestedStructMockBuffer(MockBuffer):
cdef
get_itemsize
(
self
):
return
sizeof
(
NestedStruct
)
cdef
get_default_format
(
self
):
return
b"2T{ii}i"
cdef
class
PackedStructMockBuffer
(
MockBuffer
):
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
cdef
PackedStruct
*
s
s
=
<
PackedStruct
*>
buf
;
s
.
a
,
s
.
b
=
value
return
0
cdef
get_itemsize
(
self
):
return
sizeof
(
PackedStruct
)
cdef
get_default_format
(
self
):
return
b"^ci"
cdef
class
NestedPackedStructMockBuffer
(
MockBuffer
):
cdef
int
write
(
self
,
char
*
buf
,
object
value
)
except
-
1
:
cdef
NestedPackedStruct
*
s
s
=
<
NestedPackedStruct
*>
buf
;
s
.
a
,
s
.
b
,
s
.
sub
.
a
,
s
.
sub
.
b
,
s
.
c
=
value
return
0
cdef
get_itemsize
(
self
):
return
sizeof
(
NestedPackedStruct
)
cdef
get_default_format
(
self
):
return
b"ci^ci@i"
@
testcase
def
basic_struct
(
object
[
MyStruct
]
buf
):
"""
...
...
@@ -1325,6 +1355,35 @@ def nested_struct(object[NestedStruct] buf):
"""
print
buf
[
0
].
x
.
a
,
buf
[
0
].
x
.
b
,
buf
[
0
].
y
.
a
,
buf
[
0
].
y
.
b
,
buf
[
0
].
z
@
testcase
def
packed_struct
(
object
[
PackedStruct
]
buf
):
"""
See also buffmt.pyx
>>> packed_struct(PackedStructMockBuffer(None, [(1, 2)]))
1 2
>>> packed_struct(PackedStructMockBuffer(None, [(1, 2)], format="T{c^i}"))
1 2
>>> packed_struct(PackedStructMockBuffer(None, [(1, 2)], format="T{c=i}"))
1 2
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
@
testcase
def
nested_packed_struct
(
object
[
NestedPackedStruct
]
buf
):
"""
See also buffmt.pyx
>>> nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)]))
1 2 3 4 5
>>> nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="ci^ci@i"))
1 2 3 4 5
>>> nested_packed_struct(NestedPackedStructMockBuffer(None, [(1, 2, 3, 4, 5)], format="^c@i^ci@i"))
1 2 3 4 5
"""
print
buf
[
0
].
a
,
buf
[
0
].
b
,
buf
[
0
].
sub
.
a
,
buf
[
0
].
sub
.
b
,
buf
[
0
].
c
cdef
struct
LongComplex
:
long
double
real
long
double
imag
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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