Commit 2e32985e authored by Robert Bradshaw's avatar Robert Bradshaw

Add test for unique_ptr.

parent fd1adbdf
# mode: run
# tag: cpp
from libcpp.memory cimport unique_ptr, shared_ptr
cdef extern from "cpp_smart_ptr_helper.h":
cdef cppclass CountAllocDealloc:
CountAllocDealloc(int*, int*)
def test_unique_ptr():
"""
>>> test_unique_ptr()
"""
cdef int alloc_count = 0, dealloc_count = 0
cdef unique_ptr[CountAllocDealloc] x_ptr
x_ptr.reset(new CountAllocDealloc(&alloc_count, &dealloc_count))
assert alloc_count == 1
x_ptr.reset()
assert alloc_count == 1
assert dealloc_count == 1
class CountAllocDealloc {
public:
CountAllocDealloc(int* alloc_count, int* dealloc_count)
: _alloc_count(alloc_count), _dealloc_count(dealloc_count) {
(*_alloc_count)++;
}
~CountAllocDealloc() {
(*_dealloc_count)++;
}
private:
int* _alloc_count;
int* _dealloc_count;
};
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