mirror of
https://github.com/pybind/pybind11.git
synced 2024-12-01 17:37:15 +00:00
a923419e6d
https://github.com/rwgk/pybind11/tree/xxx_value_ptr_xxx_holder Systematically exercising returning and passing unique_ptr<T>, shared_ptr<T> with unique_ptr, shared_ptr holder. Observations: test_holder_unique_ptr: make_unique_pointee OK pass_unique_pointee BUILD_FAIL (as documented) make_shared_pointee Abort free(): double free detected pass_shared_pointee RuntimeError: Unable to load a custom holder type from a default-holder instance test_holder_shared_ptr: make_unique_pointee Segmentation fault (#1138) pass_unique_pointee BUILD_FAIL (as documented) make_shared_pointee OK pass_shared_pointee OK
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# KEEP IN SYNC WITH test_holder_shared_ptr.py
|
|
import pytest
|
|
|
|
from pybind11_tests import holder_unique_ptr as m
|
|
|
|
|
|
def test_make_unique_pointee():
|
|
m.to_cout("")
|
|
m.to_cout("")
|
|
m.to_cout("make_unique_pointee")
|
|
obj = m.make_unique_pointee()
|
|
assert obj.get_int() == 213
|
|
m.to_cout("")
|
|
|
|
|
|
def test_make_shared_pointee():
|
|
m.to_cout("")
|
|
m.to_cout("")
|
|
m.to_cout("make_shared_pointee")
|
|
obj = m.make_shared_pointee()
|
|
assert obj.get_int() == 213
|
|
m.to_cout("")
|
|
|
|
|
|
def test_pass_unique_pointee():
|
|
m.to_cout("")
|
|
m.to_cout("")
|
|
m.to_cout("pass_unique_pointee")
|
|
obj = m.make_unique_pointee()
|
|
assert obj.get_int() == 213
|
|
i = m.pass_unique_pointee(obj)
|
|
assert i == 4213
|
|
m.to_cout("")
|
|
|
|
|
|
def test_pass_shared_pointee():
|
|
m.to_cout("")
|
|
m.to_cout("")
|
|
m.to_cout("pass_shared_pointee")
|
|
obj = m.make_unique_pointee()
|
|
assert obj.get_int() == 213
|
|
i = m.pass_shared_pointee(obj)
|
|
assert i == 5213
|
|
m.to_cout("")
|
|
|
|
|
|
def test_get_static_pointee():
|
|
m.to_cout("")
|
|
m.to_cout("")
|
|
m.to_cout("get_static_pointee")
|
|
obj = m.get_static_pointee()
|
|
assert obj.get_int() == 213
|
|
with pytest.raises(RuntimeError) as excinfo:
|
|
m.pass_unique_pointee(obj)
|
|
assert "Unable to cast from non-held to held instance" in str(excinfo.value)
|