Skip to content

Added a test to detect invalid RTTI caching #409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/test_inheritance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@ test_initializer inheritance([](py::module &m) {

m.def("return_class_1", []() -> BaseClass* { return new DerivedClass1(); });
m.def("return_class_2", []() -> BaseClass* { return new DerivedClass2(); });
m.def("return_class_n", [](int n) -> BaseClass* {
if (n == 1) return new DerivedClass1();
if (n == 2) return new DerivedClass2();
return new BaseClass();
});
m.def("return_none", []() -> BaseClass* { return nullptr; });
});
10 changes: 9 additions & 1 deletion tests/test_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ def test_inheritance(msg):


def test_automatic_upcasting():
from pybind11_tests import return_class_1, return_class_2, return_none
from pybind11_tests import return_class_1, return_class_2, return_class_n, return_none

assert type(return_class_1()).__name__ == "DerivedClass1"
assert type(return_class_2()).__name__ == "DerivedClass2"
assert type(return_none()).__name__ == "NoneType"
# Repeat these a few times in a random order to ensure no invalid caching is applied
assert type(return_class_n(1)).__name__ == "DerivedClass1"
assert type(return_class_n(2)).__name__ == "DerivedClass2"
assert type(return_class_n(0)).__name__ == "BaseClass"
assert type(return_class_n(2)).__name__ == "DerivedClass2"
assert type(return_class_n(2)).__name__ == "DerivedClass2"
assert type(return_class_n(0)).__name__ == "BaseClass"
assert type(return_class_n(1)).__name__ == "DerivedClass1"