SH, test for shared_ptr move

This commit is contained in:
Jakob Lykke Andersen 2021-06-19 16:35:20 +02:00 committed by Ralf W. Grosse-Kunstleve
parent c807807c55
commit 660f83e81d
4 changed files with 39 additions and 20 deletions

View File

@ -106,7 +106,7 @@ set(PYBIND11_TEST_FILES
test_class_sh_disowning_mi.cpp test_class_sh_disowning_mi.cpp
test_class_sh_factory_constructors.cpp test_class_sh_factory_constructors.cpp
test_class_sh_inheritance.cpp test_class_sh_inheritance.cpp
test_class_sh_shared_ptr_copy.cpp test_class_sh_shared_ptr_copy_move.cpp
test_class_sh_trampoline_basic.cpp test_class_sh_trampoline_basic.cpp
test_class_sh_trampoline_self_life_support.cpp test_class_sh_trampoline_self_life_support.cpp
test_class_sh_trampoline_shared_ptr_cpp_arg.cpp test_class_sh_trampoline_shared_ptr_cpp_arg.cpp

View File

@ -1,11 +0,0 @@
# -*- coding: utf-8 -*-
from pybind11_tests import class_sh_shared_ptr_copy as m
def test_avl():
m.test_avl()
def test_def():
m.test_def()

View File

@ -7,7 +7,7 @@
#include <vector> #include <vector>
namespace pybind11_tests { namespace pybind11_tests {
namespace class_sh_shared_ptr_copy { namespace class_sh_shared_ptr_copy_move {
template<int SerNo> template<int SerNo>
struct Foo { struct Foo {
@ -21,31 +21,42 @@ struct Foo {
using FooAVL = Foo<0>; using FooAVL = Foo<0>;
using FooDEF = Foo<1>; using FooDEF = Foo<1>;
} // namespace class_sh_shared_ptr_copy } // namespace class_sh_shared_ptr_copy_move
} // namespace pybind11_tests } // namespace pybind11_tests
PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_shared_ptr_copy::FooAVL) PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::class_sh_shared_ptr_copy_move::FooAVL)
namespace pybind11_tests { namespace pybind11_tests {
namespace class_sh_shared_ptr_copy { namespace class_sh_shared_ptr_copy_move {
TEST_SUBMODULE(class_sh_shared_ptr_copy, m) { TEST_SUBMODULE(class_sh_shared_ptr_copy_move, m) {
namespace py = pybind11; namespace py = pybind11;
py::class_<FooAVL, PYBIND11_SH_AVL(FooAVL)>(m, "FooAVL"); py::class_<FooAVL, PYBIND11_SH_AVL(FooAVL)>(m, "FooAVL");
py::class_<FooDEF, PYBIND11_SH_DEF(FooDEF)>(m, "FooDEF"); py::class_<FooDEF, PYBIND11_SH_DEF(FooDEF)>(m, "FooDEF");
m.def("test_avl", []() { m.def("test_avl_copy", []() {
auto o = std::make_shared<FooAVL>("AVL"); auto o = std::make_shared<FooAVL>("AVL");
auto l = py::list(); auto l = py::list();
l.append(o); l.append(o);
}); });
m.def("test_def", []() { m.def("test_def_copy", []() {
auto o = std::make_shared<FooDEF>("DEF"); auto o = std::make_shared<FooDEF>("DEF");
auto l = py::list(); auto l = py::list();
l.append(o); l.append(o);
}); });
m.def("test_avl_move", []() {
auto o = std::make_shared<FooAVL>("AVL");
auto l = py::list();
l.append(std::move(o));
});
m.def("test_def_move", []() {
auto o = std::make_shared<FooDEF>("DEF");
auto l = py::list();
l.append(std::move(o));
});
} }
} // namespace class_sh_shared_ptr_copy } // namespace class_sh_shared_ptr_copy_move
} // namespace pybind11_tests } // namespace pybind11_tests

View File

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from pybind11_tests import class_sh_shared_ptr_copy_move as m
def test_avl_copy():
m.test_avl_copy()
def test_def_copy():
m.test_def_copy()
def test_avl_move():
m.test_avl_move()
def test_def_move():
m.test_def_move()