From d76050c71344c4ae45773dd287b30508e87da924 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 6 Jan 2021 21:51:05 -0800 Subject: [PATCH] Implementing all [S]uccess tests. --- tests/core/smart_holder_poc_test.cpp | 99 +++++++++++++++++----------- 1 file changed, 62 insertions(+), 37 deletions(-) diff --git a/tests/core/smart_holder_poc_test.cpp b/tests/core/smart_holder_poc_test.cpp index 9dad8c2bb..bff9eb6bf 100644 --- a/tests/core/smart_holder_poc_test.cpp +++ b/tests/core/smart_holder_poc_test.cpp @@ -15,6 +15,10 @@ struct functor_builtin_delete { } // namespace helpers TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_unowned", "[S]") { + static int value = 19; + smart_holder hld; + hld.from_raw_ptr_unowned(&value); + REQUIRE(*hld.as_raw_ptr_unowned() == 19); } TEST_CASE("from_raw_ptr_unowned+const_value_ref", "[S]") { @@ -24,16 +28,17 @@ TEST_CASE("from_raw_ptr_unowned+const_value_ref", "[S]") { REQUIRE(hld.const_value_ref() == 19); } -TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") { -} +TEST_CASE("from_raw_ptr_unowned+as_raw_ptr_release_ownership", "[E]") {} -TEST_CASE("from_raw_ptr_unowned+as_unique_ptr", "[E]") { -} +TEST_CASE("from_raw_ptr_unowned+as_unique_ptr", "[E]") {} -TEST_CASE("from_raw_ptr_unowned+as_unique_ptr_with_deleter", "[E]") { -} +TEST_CASE("from_raw_ptr_unowned+as_unique_ptr_with_deleter", "[E]") {} TEST_CASE("from_raw_ptr_unowned+as_shared_ptr", "[S]") { + static int value = 19; + smart_holder hld; + hld.from_raw_ptr_unowned(&value); + REQUIRE(*hld.as_shared_ptr() == 19); } TEST_CASE("from_raw_ptr_take_ownership+const_value_ref", "[S]") { @@ -49,29 +54,27 @@ TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership1", "[S]") { auto new_owner = std::unique_ptr(hld.as_raw_ptr_release_ownership()); REQUIRE(!hld.has_pointee()); + REQUIRE(*new_owner == 19); } -TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership2", "[E]") { -} +TEST_CASE("from_raw_ptr_take_ownership+as_raw_ptr_release_ownership2", "[E]") {} TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr1", "[S]") { smart_holder hld; hld.from_raw_ptr_take_ownership(new int(19)); - auto new_owner = hld.as_unique_ptr(); + std::unique_ptr new_owner = hld.as_unique_ptr(); REQUIRE(!hld.has_pointee()); REQUIRE(*new_owner == 19); } -TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") { -} +TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr2", "[E]") {} -TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") { -} +TEST_CASE("from_raw_ptr_take_ownership+as_unique_ptr_with_deleter", "[E]") {} TEST_CASE("from_raw_ptr_take_ownership+as_shared_ptr", "[S]") { smart_holder hld; hld.from_raw_ptr_take_ownership(new int(19)); - auto new_owner = hld.as_shared_ptr(); + std::shared_ptr new_owner = hld.as_shared_ptr(); REQUIRE(hld.has_pointee()); REQUIRE(*new_owner == 19); } @@ -85,21 +88,40 @@ TEST_CASE("from_unique_ptr+const_value_ref", "[S]") { } TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership1", "[S]") { + std::unique_ptr orig_owner(new int(19)); + smart_holder hld; + hld.from_unique_ptr(std::move(orig_owner)); + REQUIRE(orig_owner.get() == nullptr); + auto new_owner = + std::unique_ptr(hld.as_raw_ptr_release_ownership()); + REQUIRE(!hld.has_pointee()); + REQUIRE(*new_owner == 19); } -TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership2", "[E]") { -} +TEST_CASE("from_unique_ptr+as_raw_ptr_release_ownership2", "[E]") {} TEST_CASE("from_unique_ptr+as_unique_ptr1", "[S]") { + std::unique_ptr orig_owner(new int(19)); + smart_holder hld; + hld.from_unique_ptr(std::move(orig_owner)); + REQUIRE(orig_owner.get() == nullptr); + std::unique_ptr new_owner = hld.as_unique_ptr(); + REQUIRE(!hld.has_pointee()); + REQUIRE(*new_owner == 19); } -TEST_CASE("from_unique_ptr+as_unique_ptr2", "[E]") { -} +TEST_CASE("from_unique_ptr+as_unique_ptr2", "[E]") {} -TEST_CASE("from_unique_ptr+as_unique_ptr_with_deleter", "[E]") { -} +TEST_CASE("from_unique_ptr+as_unique_ptr_with_deleter", "[E]") {} TEST_CASE("from_unique_ptr+as_shared_ptr", "[S]") { + std::unique_ptr orig_owner(new int(19)); + smart_holder hld; + hld.from_unique_ptr(std::move(orig_owner)); + REQUIRE(orig_owner.get() == nullptr); + std::shared_ptr new_owner = hld.as_shared_ptr(); + REQUIRE(hld.has_pointee()); + REQUIRE(*new_owner == 19); } TEST_CASE("from_unique_ptr_with_deleter+const_value_ref", "[S]") { @@ -111,49 +133,52 @@ TEST_CASE("from_unique_ptr_with_deleter+const_value_ref", "[S]") { REQUIRE(hld.const_value_ref() == 19); } -TEST_CASE("from_unique_ptr_with_deleter+as_raw_ptr_release_ownership", "[E]") { -} +TEST_CASE("from_unique_ptr_with_deleter+as_raw_ptr_release_ownership", "[E]") {} -TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr", "[E]") { -} +TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr", "[E]") {} TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter1", "[S]") { std::unique_ptr> orig_owner( new int(19)); smart_holder hld; hld.from_unique_ptr_with_deleter(std::move(orig_owner)); - auto new_owner = + REQUIRE(orig_owner.get() == nullptr); + std::unique_ptr> new_owner = hld.as_unique_ptr_with_deleter>(); REQUIRE(!hld.has_pointee()); REQUIRE(*new_owner == 19); } -TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter2", "[E]") { -} +TEST_CASE("from_unique_ptr_with_deleter+as_unique_ptr_with_deleter2", "[E]") {} TEST_CASE("from_unique_ptr_with_deleter+as_shared_ptr", "[S]") { + std::unique_ptr> orig_owner( + new int(19)); + smart_holder hld; + hld.from_unique_ptr_with_deleter(std::move(orig_owner)); + REQUIRE(orig_owner.get() == nullptr); + std::shared_ptr new_owner = hld.as_shared_ptr(); + REQUIRE(hld.has_pointee()); + REQUIRE(*new_owner == 19); } TEST_CASE("from_shared_ptr+const_value_ref", "[S]") { std::shared_ptr orig_owner(new int(19)); smart_holder hld; hld.from_shared_ptr(orig_owner); - REQUIRE(orig_owner.get() != nullptr); REQUIRE(hld.const_value_ref() == 19); } -TEST_CASE("from_shared_ptr+as_raw_ptr_release_ownership1", "[S]") { -} +TEST_CASE("from_shared_ptr+as_raw_ptr_release_ownership", "[E]") {} -TEST_CASE("from_shared_ptr+as_raw_ptr_release_ownership2", "[E]") { -} +TEST_CASE("from_shared_ptr+as_unique_ptr", "[E]") {} -TEST_CASE("from_shared_ptr+as_unique_ptr", "[E]") { -} - -TEST_CASE("from_shared_ptr+as_unique_ptr_with_deleter", "[E]") { -} +TEST_CASE("from_shared_ptr+as_unique_ptr_with_deleter", "[E]") {} TEST_CASE("from_shared_ptr+as_shared_ptr", "[S]") { + std::shared_ptr orig_owner(new int(19)); + smart_holder hld; + hld.from_shared_ptr(orig_owner); + REQUIRE(*hld.as_shared_ptr() == 19); }