Commit 9572cd2d authored by Xavier Thompson's avatar Xavier Thompson

Add unit test for reference count of called-on cypclass subscripts

parent da3b60f3
...@@ -8,6 +8,9 @@ cdef cypclass Value: ...@@ -8,6 +8,9 @@ cdef cypclass Value:
__dealloc__(self) with gil: __dealloc__(self) with gil:
print("Value destroyed") print("Value destroyed")
int foo(self):
return 0
def test_cpp_index_refcounting(): def test_cpp_index_refcounting():
""" """
>>> test_cpp_index_refcounting() >>> test_cpp_index_refcounting()
...@@ -58,3 +61,45 @@ def test_cyp_index_refcounting(): ...@@ -58,3 +61,45 @@ def test_cyp_index_refcounting():
if Cy_GETREF(a) != 3: if Cy_GETREF(a) != 3:
return -1 return -1
return 0 return 0
def test_call_on_cpp_index_refcounting():
"""
>>> test_call_on_cpp_index_refcounting()
Value destroyed
0
"""
cdef vector[Value] vec
val = Value()
vec.push_back(val)
vec[0].foo()
if Cy_GETREF(val) != 3:
return -1
return 0
def test_call_on_cyp_template_index_refcounting():
"""
>>> test_call_on_cyp_template_index_refcounting()
Value destroyed
0
"""
v = Vector[Value]()
val = Value()
v.vec.push_back(val)
v[0].foo()
if Cy_GETREF(val) != 3:
return -1
return 0
def test_call_on_cyp_index_refcounting():
"""
>>> test_call_on_cyp_index_refcounting()
Value destroyed
0
"""
v = ValueVector()
val = Value()
v.vec.push_back(val)
v[0].foo()
if Cy_GETREF(val) != 3:
return -1
return 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment