test_holder_shared_ptr.py 1.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
# KEEP IN SYNC WITH test_holder_unique_ptr.py
import pytest

from pybind11_tests import holder_shared_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_shared_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_shared_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_shared_pointee(obj)
    assert "Unable to cast from non-held to held instance" in str(excinfo.value)