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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
e52f7f3e
Commit
e52f7f3e
authored
Sep 05, 2020
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for cypclass refcount with templated code
parent
60313a6a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
131 additions
and
0 deletions
+131
-0
tests/run/cypclass_template_refcounting.pyx
tests/run/cypclass_template_refcounting.pyx
+131
-0
No files found.
tests/run/cypclass_template_refcounting.pyx
0 → 100644
View file @
e52f7f3e
# mode: run
# tag: cpp, cpp11, pthread
# cython: experimental_cpp_class_def=True, language_level=2
cdef
cypclass
Template
[
T
]:
T
value
__init__
(
self
,
T
value
):
self
.
value
=
value
__dealloc__
(
self
)
with
gil
:
print
(
"Template destroyed"
)
void
set
(
self
,
T
value
):
self
.
value
=
value
T
get
(
self
):
return
self
.
value
cdef
cypclass
Value
:
__dealloc__
(
self
)
with
gil
:
print
(
"Value destroyed"
)
def
test_destruction
():
"""
>>> test_destruction()
Template destroyed
Value destroyed
"""
h
=
Template
[
Value
](
Value
())
def
test_setting
():
"""
>>> test_setting()
Value destroyed
Template destroyed
0
"""
v
=
Value
()
if
Cy_GETREF
(
v
)
!=
2
:
return
-
1
h
=
Template
[
Value
](
NULL
)
if
Cy_GETREF
(
v
)
!=
2
:
return
-
2
h
.
set
(
v
)
if
Cy_GETREF
(
v
)
!=
3
:
return
-
3
h
.
set
(
NULL
)
if
Cy_GETREF
(
v
)
!=
2
:
return
-
4
return
0
def
test_deleting
():
"""
>>> test_deleting()
Template destroyed
Value destroyed
0
"""
v
=
Value
()
if
Cy_GETREF
(
v
)
!=
2
:
return
-
1
h
=
Template
[
Value
](
v
)
if
Cy_GETREF
(
v
)
!=
3
:
return
-
2
del
h
if
Cy_GETREF
(
v
)
!=
2
:
return
-
3
return
0
def
test_getting
():
"""
>>> test_getting()
Template destroyed
Value destroyed
0
"""
h
=
Template
[
Value
](
Value
())
v1
=
h
.
get
()
if
Cy_GETREF
(
v1
)
!=
3
:
return
-
1
v2
=
h
.
get
()
if
Cy_GETREF
(
v1
)
!=
4
:
return
-
2
if
Cy_GETREF
(
v2
)
!=
4
:
return
-
3
return
0
def
test_getting_inspecting_setting
():
"""
>>> test_getting_inspecting_setting()
Template destroyed
Value destroyed
0
"""
h
=
Template
[
Value
](
Value
())
for
i
in
range
(
10
):
v
=
h
.
get
()
if
Cy_GETREF
(
v
)
!=
3
:
return
-
(
i
+
1
)
h
.
set
(
v
)
return
0
def
test_getting_and_setting
():
"""
>>> test_getting_and_setting()
Template destroyed
Value destroyed
0
"""
v
=
Value
()
h
=
Template
[
Value
](
v
)
if
Cy_GETREF
(
v
)
!=
3
:
return
-
1
for
i
in
range
(
10
):
h
.
set
(
h
.
get
())
if
Cy_GETREF
(
v
)
!=
3
:
return
-
(
i
+
2
)
return
0
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