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
0f316720
Commit
0f316720
authored
Jan 29, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding comment, simplifying naming, cmake addition.
parent
0dfd3a6b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
73 deletions
+78
-73
tests/CMakeLists.txt
+1
-0
tests/test_type_caster_bare_interface.cpp
+57
-53
tests/test_type_caster_bare_interface.py
+20
-20
No files found.
tests/CMakeLists.txt
View file @
0f316720
...
@@ -132,6 +132,7 @@ set(PYBIND11_TEST_FILES
...
@@ -132,6 +132,7 @@ set(PYBIND11_TEST_FILES
test_stl.cpp
test_stl.cpp
test_stl_binders.cpp
test_stl_binders.cpp
test_tagbased_polymorphic.cpp
test_tagbased_polymorphic.cpp
test_type_caster_bare_interface.cpp
test_union.cpp
test_union.cpp
test_virtual_functions.cpp
)
test_virtual_functions.cpp
)
...
...
tests/test_type_caster_bare_interface.cpp
View file @
0f316720
// Systematically exercises the detail::type_caster<> interface. This is going a step in the
// direction of an integration test, to ensure multiple components of pybind11 work together
// correctly. It is also useful to show the type_caster<> interface virtually clutter-free.
#include "pybind11_tests.h"
#include "pybind11_tests.h"
#include <memory>
#include <memory>
...
@@ -9,31 +13,31 @@ struct mpty {};
...
@@ -9,31 +13,31 @@ struct mpty {};
// clang-format off
// clang-format off
mpty
rtrn_
mpty_
valu
()
{
mpty
obj
;
return
obj
;
}
mpty
rtrn_valu
()
{
mpty
obj
;
return
obj
;
}
mpty
&&
rtrn_
mpty_
rref
()
{
static
mpty
obj
;
return
std
::
move
(
obj
);
}
mpty
&&
rtrn_rref
()
{
static
mpty
obj
;
return
std
::
move
(
obj
);
}
mpty
const
&
rtrn_
mpty_
cref
()
{
static
mpty
obj
;
return
obj
;
}
mpty
const
&
rtrn_cref
()
{
static
mpty
obj
;
return
obj
;
}
mpty
&
rtrn_m
pty_m
ref
()
{
static
mpty
obj
;
return
obj
;
}
mpty
&
rtrn_mref
()
{
static
mpty
obj
;
return
obj
;
}
mpty
const
*
rtrn_
mpty_
cptr
()
{
return
new
mpty
;
}
mpty
const
*
rtrn_cptr
()
{
return
new
mpty
;
}
mpty
*
rtrn_mpt
y_mpt
r
()
{
return
new
mpty
;
}
mpty
*
rtrn_mptr
()
{
return
new
mpty
;
}
const
char
*
pass_
mpty_
valu
(
mpty
)
{
return
"load_valu"
;
}
const
char
*
pass_valu
(
mpty
)
{
return
"load_valu"
;
}
const
char
*
pass_
mpty_
rref
(
mpty
&&
)
{
return
"load_rref"
;
}
const
char
*
pass_rref
(
mpty
&&
)
{
return
"load_rref"
;
}
const
char
*
pass_
mpty_
cref
(
mpty
const
&
)
{
return
"load_cref"
;
}
const
char
*
pass_cref
(
mpty
const
&
)
{
return
"load_cref"
;
}
const
char
*
pass_m
pty_m
ref
(
mpty
&
)
{
return
"load_mref"
;
}
const
char
*
pass_mref
(
mpty
&
)
{
return
"load_mref"
;
}
const
char
*
pass_
mpty_
cptr
(
mpty
const
*
)
{
return
"load_cptr"
;
}
const
char
*
pass_cptr
(
mpty
const
*
)
{
return
"load_cptr"
;
}
const
char
*
pass_mpt
y_mpt
r
(
mpty
*
)
{
return
"load_mptr"
;
}
const
char
*
pass_mptr
(
mpty
*
)
{
return
"load_mptr"
;
}
std
::
shared_ptr
<
mpty
>
rtrn_
mpty_
shmp
()
{
return
std
::
shared_ptr
<
mpty
>
(
new
mpty
);
}
std
::
shared_ptr
<
mpty
>
rtrn_shmp
()
{
return
std
::
shared_ptr
<
mpty
>
(
new
mpty
);
}
std
::
shared_ptr
<
mpty
const
>
rtrn_
mpty_
shcp
()
{
return
std
::
shared_ptr
<
mpty
const
>
(
new
mpty
);
}
std
::
shared_ptr
<
mpty
const
>
rtrn_shcp
()
{
return
std
::
shared_ptr
<
mpty
const
>
(
new
mpty
);
}
const
char
*
pass_
mpty_
shmp
(
std
::
shared_ptr
<
mpty
>
)
{
return
"load_shmp"
;
}
const
char
*
pass_shmp
(
std
::
shared_ptr
<
mpty
>
)
{
return
"load_shmp"
;
}
const
char
*
pass_
mpty_
shcp
(
std
::
shared_ptr
<
mpty
const
>
)
{
return
"load_shcp"
;
}
const
char
*
pass_shcp
(
std
::
shared_ptr
<
mpty
const
>
)
{
return
"load_shcp"
;
}
std
::
unique_ptr
<
mpty
>
rtrn_
mpty_
uqmp
()
{
return
std
::
unique_ptr
<
mpty
>
(
new
mpty
);
}
std
::
unique_ptr
<
mpty
>
rtrn_uqmp
()
{
return
std
::
unique_ptr
<
mpty
>
(
new
mpty
);
}
std
::
unique_ptr
<
mpty
const
>
rtrn_
mpty_
uqcp
()
{
return
std
::
unique_ptr
<
mpty
const
>
(
new
mpty
);
}
std
::
unique_ptr
<
mpty
const
>
rtrn_uqcp
()
{
return
std
::
unique_ptr
<
mpty
const
>
(
new
mpty
);
}
const
char
*
pass_
mpty_
uqmp
(
std
::
unique_ptr
<
mpty
>
)
{
return
"load_uqmp"
;
}
const
char
*
pass_uqmp
(
std
::
unique_ptr
<
mpty
>
)
{
return
"load_uqmp"
;
}
const
char
*
pass_
mpty_
uqcp
(
std
::
unique_ptr
<
mpty
const
>
)
{
return
"load_uqcp"
;
}
const
char
*
pass_uqcp
(
std
::
unique_ptr
<
mpty
const
>
)
{
return
"load_uqcp"
;
}
// clang-format on
// clang-format on
...
@@ -90,10 +94,10 @@ struct type_caster<mpty> {
...
@@ -90,10 +94,10 @@ struct type_caster<mpty> {
// clang-format off
// clang-format off
operator
mpty
()
{
return
rtrn_
mpty_
valu
();
}
operator
mpty
()
{
return
rtrn_valu
();
}
operator
mpty
&&
()
&&
{
return
rtrn_
mpty_
rref
();
}
operator
mpty
&&
()
&&
{
return
rtrn_rref
();
}
operator
mpty
const
&
()
{
return
rtrn_
mpty_
cref
();
}
operator
mpty
const
&
()
{
return
rtrn_cref
();
}
operator
mpty
&
()
{
return
rtrn_m
pty_m
ref
();
}
operator
mpty
&
()
{
return
rtrn_mref
();
}
operator
mpty
const
*
()
{
static
mpty
obj
;
return
&
obj
;
}
operator
mpty
const
*
()
{
static
mpty
obj
;
return
&
obj
;
}
operator
mpty
*
()
{
static
mpty
obj
;
return
&
obj
;
}
operator
mpty
*
()
{
static
mpty
obj
;
return
&
obj
;
}
...
@@ -115,7 +119,7 @@ struct type_caster<std::shared_ptr<mpty>> {
...
@@ -115,7 +119,7 @@ struct type_caster<std::shared_ptr<mpty>> {
template
<
typename
>
template
<
typename
>
using
cast_op_type
=
std
::
shared_ptr
<
mpty
>
;
using
cast_op_type
=
std
::
shared_ptr
<
mpty
>
;
operator
std
::
shared_ptr
<
mpty
>
()
{
return
rtrn_
mpty_
shmp
();
}
operator
std
::
shared_ptr
<
mpty
>
()
{
return
rtrn_shmp
();
}
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
return
true
;
}
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
return
true
;
}
};
};
...
@@ -133,7 +137,7 @@ struct type_caster<std::shared_ptr<mpty const>> {
...
@@ -133,7 +137,7 @@ struct type_caster<std::shared_ptr<mpty const>> {
template
<
typename
>
template
<
typename
>
using
cast_op_type
=
std
::
shared_ptr
<
mpty
const
>
;
using
cast_op_type
=
std
::
shared_ptr
<
mpty
const
>
;
operator
std
::
shared_ptr
<
mpty
const
>
()
{
return
rtrn_
mpty_
shcp
();
}
operator
std
::
shared_ptr
<
mpty
const
>
()
{
return
rtrn_shcp
();
}
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
return
true
;
}
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
return
true
;
}
};
};
...
@@ -150,7 +154,7 @@ struct type_caster<std::unique_ptr<mpty>> {
...
@@ -150,7 +154,7 @@ struct type_caster<std::unique_ptr<mpty>> {
template
<
typename
>
template
<
typename
>
using
cast_op_type
=
std
::
unique_ptr
<
mpty
>
;
using
cast_op_type
=
std
::
unique_ptr
<
mpty
>
;
operator
std
::
unique_ptr
<
mpty
>
()
{
return
rtrn_
mpty_
uqmp
();
}
operator
std
::
unique_ptr
<
mpty
>
()
{
return
rtrn_uqmp
();
}
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
return
true
;
}
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
return
true
;
}
};
};
...
@@ -168,7 +172,7 @@ struct type_caster<std::unique_ptr<mpty const>> {
...
@@ -168,7 +172,7 @@ struct type_caster<std::unique_ptr<mpty const>> {
template
<
typename
>
template
<
typename
>
using
cast_op_type
=
std
::
unique_ptr
<
mpty
const
>
;
using
cast_op_type
=
std
::
unique_ptr
<
mpty
const
>
;
operator
std
::
unique_ptr
<
mpty
const
>
()
{
return
rtrn_
mpty_
uqcp
();
}
operator
std
::
unique_ptr
<
mpty
const
>
()
{
return
rtrn_uqcp
();
}
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
return
true
;
}
bool
load
(
handle
/*src*/
,
bool
/*convert*/
)
{
return
true
;
}
};
};
...
@@ -180,31 +184,31 @@ namespace pybind11_tests {
...
@@ -180,31 +184,31 @@ namespace pybind11_tests {
namespace
type_caster_bare_interface
{
namespace
type_caster_bare_interface
{
TEST_SUBMODULE
(
type_caster_bare_interface
,
m
)
{
TEST_SUBMODULE
(
type_caster_bare_interface
,
m
)
{
m
.
def
(
"rtrn_
mpty_valu"
,
rtrn_mpty
_valu
);
m
.
def
(
"rtrn_
valu"
,
rtrn
_valu
);
m
.
def
(
"rtrn_
mpty_rref"
,
rtrn_mpty
_rref
);
m
.
def
(
"rtrn_
rref"
,
rtrn
_rref
);
m
.
def
(
"rtrn_
mpty_cref"
,
rtrn_mpty
_cref
);
m
.
def
(
"rtrn_
cref"
,
rtrn
_cref
);
m
.
def
(
"rtrn_m
pty_mref"
,
rtrn_mpty
_mref
);
m
.
def
(
"rtrn_m
ref"
,
rtrn
_mref
);
m
.
def
(
"rtrn_
mpty_cptr"
,
rtrn_mpty
_cptr
);
m
.
def
(
"rtrn_
cptr"
,
rtrn
_cptr
);
m
.
def
(
"rtrn_mpt
y_mptr"
,
rtrn_mpty
_mptr
);
m
.
def
(
"rtrn_mpt
r"
,
rtrn
_mptr
);
m
.
def
(
"pass_
mpty_valu"
,
pass_mpty
_valu
);
m
.
def
(
"pass_
valu"
,
pass
_valu
);
m
.
def
(
"pass_
mpty_rref"
,
pass_mpty
_rref
);
m
.
def
(
"pass_
rref"
,
pass
_rref
);
m
.
def
(
"pass_
mpty_cref"
,
pass_mpty
_cref
);
m
.
def
(
"pass_
cref"
,
pass
_cref
);
m
.
def
(
"pass_m
pty_mref"
,
pass_mpty
_mref
);
m
.
def
(
"pass_m
ref"
,
pass
_mref
);
m
.
def
(
"pass_
mpty_cptr"
,
pass_mpty
_cptr
);
m
.
def
(
"pass_
cptr"
,
pass
_cptr
);
m
.
def
(
"pass_mpt
y_mptr"
,
pass_mpty
_mptr
);
m
.
def
(
"pass_mpt
r"
,
pass
_mptr
);
m
.
def
(
"rtrn_
mpty_shmp"
,
rtrn_mpty
_shmp
);
m
.
def
(
"rtrn_
shmp"
,
rtrn
_shmp
);
m
.
def
(
"rtrn_
mpty_shcp"
,
rtrn_mpty
_shcp
);
m
.
def
(
"rtrn_
shcp"
,
rtrn
_shcp
);
m
.
def
(
"pass_
mpty_shmp"
,
pass_mpty
_shmp
);
m
.
def
(
"pass_
shmp"
,
pass
_shmp
);
m
.
def
(
"pass_
mpty_shcp"
,
pass_mpty
_shcp
);
m
.
def
(
"pass_
shcp"
,
pass
_shcp
);
m
.
def
(
"rtrn_
mpty_uqmp"
,
rtrn_mpty
_uqmp
);
m
.
def
(
"rtrn_
uqmp"
,
rtrn
_uqmp
);
m
.
def
(
"rtrn_
mpty_uqcp"
,
rtrn_mpty
_uqcp
);
m
.
def
(
"rtrn_
uqcp"
,
rtrn
_uqcp
);
m
.
def
(
"pass_
mpty_uqmp"
,
pass_mpty
_uqmp
);
m
.
def
(
"pass_
uqmp"
,
pass
_uqmp
);
m
.
def
(
"pass_
mpty_uqcp"
,
pass_mpty
_uqcp
);
m
.
def
(
"pass_
uqcp"
,
pass
_uqcp
);
}
}
}
// namespace type_caster_bare_interface
}
// namespace type_caster_bare_interface
...
...
tests/test_type_caster_bare_interface.py
View file @
0f316720
...
@@ -4,38 +4,38 @@ from pybind11_tests import type_caster_bare_interface as m
...
@@ -4,38 +4,38 @@ from pybind11_tests import type_caster_bare_interface as m
def
test_cast
():
def
test_cast
():
assert
m
.
rtrn_
mpty_
valu
()
==
"cast_rref"
assert
m
.
rtrn_valu
()
==
"cast_rref"
assert
m
.
rtrn_
mpty_
rref
()
==
"cast_rref"
assert
m
.
rtrn_rref
()
==
"cast_rref"
assert
m
.
rtrn_
mpty_
cref
()
==
"cast_cref"
assert
m
.
rtrn_cref
()
==
"cast_cref"
assert
m
.
rtrn_m
pty_m
ref
()
==
"cast_mref"
assert
m
.
rtrn_mref
()
==
"cast_mref"
assert
m
.
rtrn_
mpty_
cptr
()
==
"cast_cptr"
assert
m
.
rtrn_cptr
()
==
"cast_cptr"
assert
m
.
rtrn_mpt
y_mpt
r
()
==
"cast_mptr"
assert
m
.
rtrn_mptr
()
==
"cast_mptr"
def
test_load
():
def
test_load
():
assert
m
.
pass_
mpty_
valu
(
None
)
==
"load_valu"
assert
m
.
pass_valu
(
None
)
==
"load_valu"
assert
m
.
pass_
mpty_
rref
(
None
)
==
"load_rref"
assert
m
.
pass_rref
(
None
)
==
"load_rref"
assert
m
.
pass_
mpty_
cref
(
None
)
==
"load_cref"
assert
m
.
pass_cref
(
None
)
==
"load_cref"
assert
m
.
pass_m
pty_m
ref
(
None
)
==
"load_mref"
assert
m
.
pass_mref
(
None
)
==
"load_mref"
assert
m
.
pass_
mpty_
cptr
(
None
)
==
"load_cptr"
assert
m
.
pass_cptr
(
None
)
==
"load_cptr"
assert
m
.
pass_mpt
y_mpt
r
(
None
)
==
"load_mptr"
assert
m
.
pass_mptr
(
None
)
==
"load_mptr"
def
test_cast_shared_ptr
():
def
test_cast_shared_ptr
():
assert
m
.
rtrn_
mpty_
shmp
()
==
"cast_shmp"
assert
m
.
rtrn_shmp
()
==
"cast_shmp"
assert
m
.
rtrn_
mpty_
shcp
()
==
"cast_shcp"
assert
m
.
rtrn_shcp
()
==
"cast_shcp"
def
test_load_shared_ptr
():
def
test_load_shared_ptr
():
assert
m
.
pass_
mpty_
shmp
(
None
)
==
"load_shmp"
assert
m
.
pass_shmp
(
None
)
==
"load_shmp"
assert
m
.
pass_
mpty_
shcp
(
None
)
==
"load_shcp"
assert
m
.
pass_shcp
(
None
)
==
"load_shcp"
def
test_cast_unique_ptr
():
def
test_cast_unique_ptr
():
assert
m
.
rtrn_
mpty_
uqmp
()
==
"cast_uqmp"
assert
m
.
rtrn_uqmp
()
==
"cast_uqmp"
assert
m
.
rtrn_
mpty_
uqcp
()
==
"cast_uqcp"
assert
m
.
rtrn_uqcp
()
==
"cast_uqcp"
def
test_load_unique_ptr
():
def
test_load_unique_ptr
():
assert
m
.
pass_
mpty_
uqmp
(
None
)
==
"load_uqmp"
assert
m
.
pass_uqmp
(
None
)
==
"load_uqmp"
assert
m
.
pass_
mpty_
uqcp
(
None
)
==
"load_uqcp"
assert
m
.
pass_uqcp
(
None
)
==
"load_uqcp"
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