2020-11-17 20:19:19 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from pybind11_tests import unique_ptr_member as m
|
|
|
|
|
|
|
|
|
2020-11-20 02:33:37 +00:00
|
|
|
def test_make_unique_pointee():
|
|
|
|
m.to_cout("")
|
|
|
|
obj = m.make_unique_pointee()
|
|
|
|
assert obj.get_int() == 213
|
|
|
|
m.to_cout("")
|
2020-11-17 20:19:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_pointee_and_ptr_owner():
|
2020-11-20 02:33:37 +00:00
|
|
|
m.to_cout("")
|
2020-11-17 20:19:19 +00:00
|
|
|
obj = m.pointee()
|
|
|
|
assert obj.get_int() == 213
|
2020-11-20 02:33:37 +00:00
|
|
|
owner = m.ptr_owner(obj)
|
|
|
|
with pytest.raises(RuntimeError) as exc_info:
|
2020-11-17 20:19:19 +00:00
|
|
|
obj.get_int()
|
2020-11-20 02:33:37 +00:00
|
|
|
assert str(exc_info.value) == "Invalid object instance"
|
|
|
|
assert owner.is_owner()
|
|
|
|
m.to_cout("before give up")
|
|
|
|
reclaimed = owner.give_up_ownership_via_shared_ptr()
|
|
|
|
m.to_cout("after give up")
|
|
|
|
assert not owner.is_owner()
|
|
|
|
# assert reclaimed.get_int() == 213
|
|
|
|
del reclaimed
|
|
|
|
m.to_cout("after del")
|
|
|
|
m.to_cout("3")
|
|
|
|
m.to_cout("")
|
|
|
|
|
|
|
|
|
|
|
|
def test_cpp_pattern():
|
|
|
|
m.to_cout("")
|
|
|
|
res = m.cpp_pattern()
|
|
|
|
assert res == 111111
|
|
|
|
m.to_cout("")
|