MCPcopy Create free account
hub / github.com/pybind/pybind11 / TEST_SUBMODULE

Function TEST_SUBMODULE

tests/test_class_sh_trampoline_self_life_support.cpp:49–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47using namespace pybind11_tests::class_sh_trampoline_self_life_support;
48
49TEST_SUBMODULE(class_sh_trampoline_self_life_support, m) {
50 py::classh<Big5, Big5Trampoline>(m, "Big5")
51 .def(py::init<std::string>())
52 .def_readonly("history", &Big5::history);
53
54 m.def("action", [](std::unique_ptr<Big5> obj, int action_id) {
55 py::object o2 = py::none();
56 // This is very unusual, but needed to directly exercise the trampoline_self_life_support
57 // CpCtor, MvCtor, operator= lvalue, operator= rvalue.
58 auto *obj_trampoline = dynamic_cast<Big5Trampoline *>(obj.get());
59 if (obj_trampoline != nullptr) {
60 switch (action_id) {
61 case 0: { // CpCtor
62 std::unique_ptr<Big5> cp(new Big5Trampoline(*obj_trampoline));
63 o2 = py::cast(std::move(cp));
64 } break;
65 case 1: { // MvCtor
66 std::unique_ptr<Big5> mv(new Big5Trampoline(std::move(*obj_trampoline)));
67 o2 = py::cast(std::move(mv));
68 } break;
69 case 2: { // operator= lvalue
70 std::unique_ptr<Big5> lv(new Big5Trampoline);
71 *lv = *obj_trampoline; // NOLINT clang-tidy cppcoreguidelines-slicing
72 o2 = py::cast(std::move(lv));
73 } break;
74 case 3: { // operator= rvalue
75 std::unique_ptr<Big5> rv(new Big5Trampoline);
76 *rv = std::move(*obj_trampoline);
77 o2 = py::cast(std::move(rv));
78 } break;
79 default:
80 break;
81 }
82 }
83 py::object o1 = py::cast(std::move(obj));
84 return py::make_tuple(o1, o2);
85 });
86}

Callers

nothing calls this directly

Calls 5

noneClass · 0.85
moveFunction · 0.85
make_tupleFunction · 0.85
castFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected