Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
591a9999
Commit
591a9999
authored
Sep 12, 2016
by
Wenzel Jakob
Committed by
GitHub
Sep 12, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #409 from jagerman/dynamic-cast-test
Added a test to detect invalid RTTI caching
parents
f2268380
0e489777
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
1 deletions
+14
-1
tests/test_inheritance.cpp
+5
-0
tests/test_inheritance.py
+9
-1
No files found.
tests/test_inheritance.cpp
View file @
591a9999
...
...
@@ -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
;
});
});
tests/test_inheritance.py
View file @
591a9999
...
...
@@ -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"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment