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
940d7935
Commit
940d7935
authored
Dec 07, 2020
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding test_get_static_pointee (works as desired for shared_ptr holder)
parent
09db57a3
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
2 deletions
+44
-2
tests/test_holder_shared_ptr.cpp
+8
-0
tests/test_holder_shared_ptr.py
+14
-1
tests/test_holder_unique_ptr.cpp
+8
-0
tests/test_holder_unique_ptr.py
+14
-1
No files found.
tests/test_holder_shared_ptr.cpp
View file @
940d7935
...
@@ -44,6 +44,11 @@ inline int pass_shared_pointee(std::shared_ptr<pointee> ptr) {
...
@@ -44,6 +44,11 @@ inline int pass_shared_pointee(std::shared_ptr<pointee> ptr) {
return
5000
+
ptr
->
get_int
();
return
5000
+
ptr
->
get_int
();
}
}
inline
pointee
*
get_static_pointee
()
{
static
pointee
cpp_instance
;
return
&
cpp_instance
;
}
TEST_SUBMODULE
(
holder_shared_ptr
,
m
)
{
TEST_SUBMODULE
(
holder_shared_ptr
,
m
)
{
m
.
def
(
"to_cout"
,
to_cout
);
m
.
def
(
"to_cout"
,
to_cout
);
...
@@ -55,6 +60,9 @@ TEST_SUBMODULE(holder_shared_ptr, m) {
...
@@ -55,6 +60,9 @@ TEST_SUBMODULE(holder_shared_ptr, m) {
m
.
def
(
"make_shared_pointee"
,
make_shared_pointee
);
m
.
def
(
"make_shared_pointee"
,
make_shared_pointee
);
// m.def("pass_unique_pointee", pass_unique_pointee);
// m.def("pass_unique_pointee", pass_unique_pointee);
m
.
def
(
"pass_shared_pointee"
,
pass_shared_pointee
);
m
.
def
(
"pass_shared_pointee"
,
pass_shared_pointee
);
m
.
def
(
"get_static_pointee"
,
get_static_pointee
,
py
::
return_value_policy
::
reference
);
}
}
}
// namespace holder_shared_ptr
}
// namespace holder_shared_ptr
...
...
tests/test_holder_shared_ptr.py
View file @
940d7935
# KEEP IN SYNC WITH test_holder_unique_ptr.py
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# KEEP IN SYNC WITH test_holder_unique_ptr.py
import
pytest
from
pybind11_tests
import
holder_shared_ptr
as
m
from
pybind11_tests
import
holder_shared_ptr
as
m
...
@@ -41,3 +43,14 @@ def test_pass_shared_pointee():
...
@@ -41,3 +43,14 @@ def test_pass_shared_pointee():
i
=
m
.
pass_shared_pointee
(
obj
)
i
=
m
.
pass_shared_pointee
(
obj
)
assert
i
==
5213
assert
i
==
5213
m
.
to_cout
(
""
)
m
.
to_cout
(
""
)
def
test_get_static_pointee
():
m
.
to_cout
(
""
)
m
.
to_cout
(
""
)
m
.
to_cout
(
"get_static_pointee"
)
obj
=
m
.
get_static_pointee
()
assert
obj
.
get_int
()
==
213
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
m
.
pass_shared_pointee
(
obj
)
assert
"Unable to cast from non-held to held instance"
in
str
(
excinfo
.
value
)
tests/test_holder_unique_ptr.cpp
View file @
940d7935
...
@@ -44,6 +44,11 @@ inline int pass_shared_pointee(std::shared_ptr<pointee> ptr) {
...
@@ -44,6 +44,11 @@ inline int pass_shared_pointee(std::shared_ptr<pointee> ptr) {
return
5000
+
ptr
->
get_int
();
return
5000
+
ptr
->
get_int
();
}
}
inline
pointee
*
get_static_pointee
()
{
static
pointee
cpp_instance
;
return
&
cpp_instance
;
}
TEST_SUBMODULE
(
holder_unique_ptr
,
m
)
{
TEST_SUBMODULE
(
holder_unique_ptr
,
m
)
{
m
.
def
(
"to_cout"
,
to_cout
);
m
.
def
(
"to_cout"
,
to_cout
);
...
@@ -55,6 +60,9 @@ TEST_SUBMODULE(holder_unique_ptr, m) {
...
@@ -55,6 +60,9 @@ TEST_SUBMODULE(holder_unique_ptr, m) {
m
.
def
(
"make_shared_pointee"
,
make_shared_pointee
);
m
.
def
(
"make_shared_pointee"
,
make_shared_pointee
);
// m.def("pass_unique_pointee", pass_unique_pointee);
// m.def("pass_unique_pointee", pass_unique_pointee);
m
.
def
(
"pass_shared_pointee"
,
pass_shared_pointee
);
m
.
def
(
"pass_shared_pointee"
,
pass_shared_pointee
);
m
.
def
(
"get_static_pointee"
,
get_static_pointee
,
py
::
return_value_policy
::
reference
);
}
}
}
// namespace holder_unique_ptr
}
// namespace holder_unique_ptr
...
...
tests/test_holder_unique_ptr.py
View file @
940d7935
# KEEP IN SYNC WITH test_holder_shared_ptr.py
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# KEEP IN SYNC WITH test_holder_shared_ptr.py
import
pytest
from
pybind11_tests
import
holder_unique_ptr
as
m
from
pybind11_tests
import
holder_unique_ptr
as
m
...
@@ -41,3 +43,14 @@ def test_pass_shared_pointee():
...
@@ -41,3 +43,14 @@ def test_pass_shared_pointee():
i
=
m
.
pass_shared_pointee
(
obj
)
i
=
m
.
pass_shared_pointee
(
obj
)
assert
i
==
5213
assert
i
==
5213
m
.
to_cout
(
""
)
m
.
to_cout
(
""
)
def
test_get_static_pointee
():
m
.
to_cout
(
""
)
m
.
to_cout
(
""
)
m
.
to_cout
(
"get_static_pointee"
)
obj
=
m
.
get_static_pointee
()
assert
obj
.
get_int
()
==
213
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
m
.
pass_unique_pointee
(
obj
)
assert
"Unable to cast from non-held to held instance"
in
str
(
excinfo
.
value
)
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