Skip to content

Commit

Permalink
adding test_promotion_of_disowned_to_shared
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Dec 4, 2020
1 parent b96ceac commit 1f4f5e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tests/test_variant_unique_shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ TEST_SUBMODULE(variant_unique_shared, m) {
v.get_unique();
return;
})
.def("get_shared", [](vptr<double> &v) {
v.get_shared();
.def("get_shared",
[](vptr<double> &v) {
v.get_shared();
return;
})
.def("disown_unique", [](vptr<double> &v) {
v.get_unique().reset();
return;
});
}
Expand Down
11 changes: 11 additions & 0 deletions tests/test_variant_unique_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ def test_shared_from_birth():
v.get_unique()
assert str(exc_info.value) == "get_unique failure."
v.get_shared() # Still works.


def test_promotion_of_disowned_to_shared():
v = m.from_unique()
assert v.get_value() == 5
v.disown_unique()
assert v.ownership_type() == 0
assert v.get_value() == -1
v.get_shared() # Promotion of disowned to shared_ptr.
assert v.ownership_type() == 1
assert v.get_value() == -1

0 comments on commit 1f4f5e2

Please sign in to comment.