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
c29134cd
Commit
c29134cd
authored
Jan 18, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding test_classh_inheritance, currently failing (passes with class_).
parent
238cc122
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
0 deletions
+62
-0
tests/test_classh_inheritance.cpp
+45
-0
tests/test_classh_inheritance.py
+17
-0
No files found.
tests/test_classh_inheritance.cpp
0 → 100644
View file @
c29134cd
#include "pybind11_tests.h"
#include <pybind11/classh.h>
namespace
pybind11_tests
{
namespace
classh_inheritance
{
struct
base
{
base
()
:
base_id
(
100
)
{}
virtual
~
base
()
=
default
;
virtual
int
id
()
const
{
return
base_id
;
}
int
base_id
;
};
struct
drvd
:
base
{
int
id
()
const
override
{
return
2
*
base_id
;
}
};
inline
drvd
*
make_drvd
()
{
return
new
drvd
;
}
inline
base
*
make_drvd_up_cast
()
{
return
new
drvd
;
}
inline
int
pass_base
(
const
base
*
b
)
{
return
b
->
id
();
}
inline
int
pass_drvd
(
const
drvd
*
d
)
{
return
d
->
id
();
}
}
// namespace classh_inheritance
}
// namespace pybind11_tests
PYBIND11_CLASSH_TYPE_CASTERS
(
pybind11_tests
::
classh_inheritance
::
base
)
PYBIND11_CLASSH_TYPE_CASTERS
(
pybind11_tests
::
classh_inheritance
::
drvd
)
namespace
pybind11_tests
{
namespace
classh_inheritance
{
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
);
}
}
// namespace classh_inheritance
}
// namespace pybind11_tests
tests/test_classh_inheritance.py
0 → 100644
View file @
c29134cd
# -*- coding: utf-8 -*-
from
pybind11_tests
import
classh_inheritance
as
m
def
test_make_drvd_pass_base
():
d
=
m
.
make_drvd
()
i
=
m
.
pass_base
(
d
)
assert
i
==
200
def
test_make_drvd_up_cast_pass_drvd
():
b
=
m
.
make_drvd_up_cast
()
# the base return is down-cast immediately.
assert
b
.
__class__
.
__name__
==
"drvd"
i
=
m
.
pass_drvd
(
b
)
assert
i
==
200
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