Skip to content

Commit

Permalink
Add minimal tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Jan 22, 2024
1 parent a894a66 commit 36d145c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ set(PYBIND11_TEST_FILES
test_stl_binders
test_tagbased_polymorphic
test_thread
test_type_caster_addressof
test_type_caster_odr_guard_1
test_type_caster_odr_guard_2
test_type_caster_pyobject_ptr
Expand Down
35 changes: 35 additions & 0 deletions tests/test_type_caster_addressof.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <pybind11/smart_holder.h>

#include "pybind11_tests.h"

namespace pybind11_tests {
namespace type_caster_addressof {

struct UnusualOpRefReturnType {};

template <int> // Using int as a trick to easily generate a series of types.
struct UnusualOpRef {
UnusualOpRefReturnType operator&() { return UnusualOpRefReturnType(); }
};

} // namespace type_caster_addressof
} // namespace pybind11_tests

PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::type_caster_addressof::UnusualOpRef<1>)

namespace pybind11_tests {
namespace type_caster_addressof {

py::object PassMovable0(UnusualOpRef<0> &&mvbl) { return py::cast(std::move(mvbl)); }
py::object PassMovable1(UnusualOpRef<1> &&mvbl) { return py::cast(std::move(mvbl)); }

} // namespace type_caster_addressof
} // namespace pybind11_tests

TEST_SUBMODULE(type_caster_addressof, m) {
using namespace pybind11_tests::type_caster_addressof;
py::class_<UnusualOpRef<0>>(m, "UnusualOpRef0");
py::classh<UnusualOpRef<1>>(m, "UnusualOpRef1");
m.def("CallPassMovable0", []() { return PassMovable0(UnusualOpRef<0>()); });
m.def("CallPassMovable1", []() { return PassMovable1(UnusualOpRef<1>()); });
}
6 changes: 6 additions & 0 deletions tests/test_type_caster_addressof.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pybind11_tests import type_caster_addressof as m


def test_merely_that_it_actually_built():
assert m.CallPassMovable0().__class__.__name__ == "UnusualOpRef0"
assert m.CallPassMovable1().__class__.__name__ == "UnusualOpRef1"

0 comments on commit 36d145c

Please sign in to comment.