Pure renaming of function names in test_classh_inheritance, similar to the systematic approach used in test_class_wip. NO functional changes.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-01-23 08:27:03 -08:00
parent cbebb6da1f
commit 54fa191f20
2 changed files with 42 additions and 37 deletions

View File

@ -20,11 +20,11 @@ struct drvd : base {
};
// clang-format off
inline drvd *make_drvd() { return new drvd; }
inline base *make_drvd_up_cast() { return new drvd; }
inline drvd *rtrn_mptr_drvd() { return new drvd; }
inline base *rtrn_mptr_drvd_up_cast() { return new drvd; }
inline int pass_base(const base *b) { return b->id() + 11; }
inline int pass_drvd(const drvd *d) { return d->id() + 12; }
inline int pass_cptr_base(const base *b) { return b->id() + 11; }
inline int pass_cptr_drvd(const drvd *d) { return d->id() + 12; }
// clang-format on
using base1 = base_template<110>;
@ -36,13 +36,13 @@ struct drvd2 : base1, base2 {
};
// clang-format off
inline drvd2 *make_drvd2() { return new drvd2; }
inline base1 *make_drvd2_up_cast1() { return new drvd2; }
inline base2 *make_drvd2_up_cast2() { return new drvd2; }
inline drvd2 *rtrn_mptr_drvd2() { return new drvd2; }
inline base1 *rtrn_mptr_drvd2_up_cast1() { return new drvd2; }
inline base2 *rtrn_mptr_drvd2_up_cast2() { return new drvd2; }
inline int pass_base1(const base1 *b) { return b->id() + 21; }
inline int pass_base2(const base2 *b) { return b->id() + 22; }
inline int pass_drvd2(const drvd2 *d) { return d->id() + 23; }
inline int pass_cptr_base1(const base1 *b) { return b->id() + 21; }
inline int pass_cptr_base2(const base2 *b) { return b->id() + 22; }
inline int pass_cptr_drvd2(const drvd2 *d) { return d->id() + 23; }
// clang-format on
} // namespace classh_inheritance
@ -62,21 +62,26 @@ TEST_SUBMODULE(classh_inheritance, m) {
py::classh<base>(m, "base");
py::classh<drvd, base>(m, "drvd");
m.def("make_drvd", make_drvd, py::return_value_policy::take_ownership);
m.def("make_drvd_up_cast", make_drvd_up_cast, py::return_value_policy::take_ownership);
m.def("pass_base", pass_base);
m.def("pass_drvd", pass_drvd);
m.def("rtrn_mptr_drvd", rtrn_mptr_drvd, py::return_value_policy::take_ownership);
m.def(
"rtrn_mptr_drvd_up_cast", rtrn_mptr_drvd_up_cast, py::return_value_policy::take_ownership);
m.def("pass_cptr_base", pass_cptr_base);
m.def("pass_cptr_drvd", pass_cptr_drvd);
py::classh<base1>(m, "base1").def(py::init<>()); // __init__ needed for Python inheritance.
py::classh<base2>(m, "base2").def(py::init<>());
py::classh<drvd2, base1, base2>(m, "drvd2");
m.def("make_drvd2", make_drvd2, py::return_value_policy::take_ownership);
m.def("make_drvd2_up_cast1", make_drvd2_up_cast1, py::return_value_policy::take_ownership);
m.def("make_drvd2_up_cast2", make_drvd2_up_cast2, py::return_value_policy::take_ownership);
m.def("pass_base1", pass_base1);
m.def("pass_base2", pass_base2);
m.def("pass_drvd2", pass_drvd2);
m.def("rtrn_mptr_drvd2", rtrn_mptr_drvd2, py::return_value_policy::take_ownership);
m.def("rtrn_mptr_drvd2_up_cast1",
rtrn_mptr_drvd2_up_cast1,
py::return_value_policy::take_ownership);
m.def("rtrn_mptr_drvd2_up_cast2",
rtrn_mptr_drvd2_up_cast2,
py::return_value_policy::take_ownership);
m.def("pass_cptr_base1", pass_cptr_base1);
m.def("pass_cptr_base2", pass_cptr_base2);
m.def("pass_cptr_drvd2", pass_cptr_drvd2);
}
} // namespace classh_inheritance

View File

@ -3,36 +3,36 @@
from pybind11_tests import classh_inheritance as m
def test_make_drvd_pass_base():
d = m.make_drvd()
i = m.pass_base(d) # load_impl Case 2a
def test_rtrn_mptr_drvd_pass_cptr_base():
d = m.rtrn_mptr_drvd()
i = m.pass_cptr_base(d) # load_impl Case 2a
assert i == 2 * 100 + 11
def test_make_drvd_up_cast_pass_drvd():
b = m.make_drvd_up_cast()
def test_rtrn_mptr_drvd_up_cast_pass_cptr_drvd():
b = m.rtrn_mptr_drvd_up_cast()
# the base return is down-cast immediately.
assert b.__class__.__name__ == "drvd"
i = m.pass_drvd(b)
i = m.pass_cptr_drvd(b)
assert i == 2 * 100 + 12
def test_make_drvd2_pass_bases():
d = m.make_drvd2()
i1 = m.pass_base1(d) # load_impl Case 2c
def test_rtrn_mptr_drvd2_pass_cptr_bases():
d = m.rtrn_mptr_drvd2()
i1 = m.pass_cptr_base1(d) # load_impl Case 2c
assert i1 == 3 * 110 + 4 * 120 + 21
i2 = m.pass_base2(d)
i2 = m.pass_cptr_base2(d)
assert i2 == 3 * 110 + 4 * 120 + 22
def test_make_drvd2_up_casts_pass_drvd2():
b1 = m.make_drvd2_up_cast1()
def test_rtrn_mptr_drvd2_up_casts_pass_cptr_drvd2():
b1 = m.rtrn_mptr_drvd2_up_cast1()
assert b1.__class__.__name__ == "drvd2"
i1 = m.pass_drvd2(b1)
i1 = m.pass_cptr_drvd2(b1)
assert i1 == 3 * 110 + 4 * 120 + 23
b2 = m.make_drvd2_up_cast2()
b2 = m.rtrn_mptr_drvd2_up_cast2()
assert b2.__class__.__name__ == "drvd2"
i2 = m.pass_drvd2(b2)
i2 = m.pass_cptr_drvd2(b2)
assert i2 == 3 * 110 + 4 * 120 + 23
@ -43,7 +43,7 @@ def test_python_drvd2():
m.base2.__init__(self)
d = Drvd2()
i1 = m.pass_base1(d) # load_impl Case 2b
i1 = m.pass_cptr_base1(d) # load_impl Case 2b
assert i1 == 110 + 21
i2 = m.pass_base2(d)
i2 = m.pass_cptr_base2(d)
assert i2 == 120 + 22