diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 491f215cef..b678fd7bf5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -156,7 +156,8 @@ set(PYBIND11_TEST_FILES test_tagbased_polymorphic test_thread test_union - test_virtual_functions) + test_virtual_functions + test_mi_debug) # Invoking cmake with something like: # cmake -DPYBIND11_TEST_OVERRIDE="test_callbacks.cpp;test_pickling.cpp" .. diff --git a/tests/test_mi_debug.cpp b/tests/test_mi_debug.cpp new file mode 100644 index 0000000000..c475314ca3 --- /dev/null +++ b/tests/test_mi_debug.cpp @@ -0,0 +1,53 @@ +#include + +#include "pybind11_tests.h" + +#include +#include +#include + +// The first base class. +struct Base0 { + virtual ~Base0() = default; +}; + +using Base0Ptr = std::shared_ptr; + +// The second base class. +struct Base1 { + virtual ~Base1() = default; + std::vector vec = {1, 2, 3, 4, 5}; +}; + +using Base1Ptr = std::shared_ptr; + +// The derived class. +struct Derived : Base1, Base0 { + ~Derived() override = default; +}; + +using DerivedPtr = std::shared_ptr; + +TEST_SUBMODULE(mi_debug, m) { + // Expose the bases. + pybind11::class_ bs0(m, "Base0"); + pybind11::class_ bs1(m, "Base1"); + // Expose the derived class. + pybind11::class_(m, "Derived").def(pybind11::init<>()); + + // A helper that returns a pointer to base. + m.def("make_object", []() -> Base0Ptr { + auto ret_der = std::make_shared(); + std::cout << "ret der ptr: " << ret_der.get() << std::endl; + auto ret = Base0Ptr(ret_der); + std::cout << "ret base ptr: " << ret.get() << std::endl; + return ret; + }); + + // A helper that accepts in input a pointer to derived. + m.def("get_object_vec_size", [](const DerivedPtr &object) { + std::cout << "der ptr: " << object.get() << std::endl; + std::cout << object->vec.size() << std::endl; + return object->vec.size(); + }); +} diff --git a/tests/test_mi_debug.py b/tests/test_mi_debug.py new file mode 100644 index 0000000000..d4acc87653 --- /dev/null +++ b/tests/test_mi_debug.py @@ -0,0 +1,8 @@ +import pytest + +m = pytest.importorskip("pybind11_tests.mi_debug") + + +def test_vec(): + o = m.make_object() + assert 5 == m.get_object_vec_size(o)