@@ -3589,7 +3589,6 @@ TEST_CASE("static pointer cast observer copy from null", "[pointer_cast]") {
35893589 REQUIRE (mem_track.double_del () == 0u );
35903590}
35913591
3592-
35933592TEST_CASE (" static pointer cast observer move from valid" , " [pointer_cast]" ) {
35943593 memory_tracker mem_track;
35953594
@@ -3625,3 +3624,146 @@ TEST_CASE("static pointer cast observer move from null", "[pointer_cast]") {
36253624 REQUIRE (mem_track.leaks () == 0u );
36263625 REQUIRE (mem_track.double_del () == 0u );
36273626}
3627+
3628+ TEST_CASE (" const pointer cast unique from valid" , " [pointer_cast]" ) {
3629+ memory_tracker mem_track;
3630+
3631+ {
3632+ test_object* raw_ptr = new test_object;
3633+ test_ptr_const ptr_orig{raw_ptr};
3634+ test_ptr ptr = oup::const_pointer_cast<test_object>(std::move (ptr_orig));
3635+
3636+ REQUIRE (instances == 1 );
3637+ REQUIRE (ptr_orig == nullptr );
3638+ REQUIRE (ptr.get () == raw_ptr);
3639+ }
3640+
3641+ REQUIRE (instances == 0 );
3642+ REQUIRE (mem_track.leaks () == 0u );
3643+ REQUIRE (mem_track.double_del () == 0u );
3644+ }
3645+
3646+ TEST_CASE (" const pointer cast unique from null" , " [pointer_cast]" ) {
3647+ memory_tracker mem_track;
3648+
3649+ {
3650+ test_ptr_const ptr_orig;
3651+ test_ptr ptr = oup::const_pointer_cast<test_object>(std::move (ptr_orig));
3652+
3653+ REQUIRE (instances == 0 );
3654+ REQUIRE (ptr_orig == nullptr );
3655+ REQUIRE (ptr == nullptr );
3656+ }
3657+
3658+ REQUIRE (instances == 0 );
3659+ REQUIRE (mem_track.leaks () == 0u );
3660+ REQUIRE (mem_track.double_del () == 0u );
3661+ }
3662+
3663+ TEST_CASE (" const pointer cast sealed from valid" , " [pointer_cast]" ) {
3664+ memory_tracker mem_track;
3665+
3666+ {
3667+ test_sptr ptr_init = oup::make_observable_sealed<test_object>();
3668+ test_object* raw_ptr = ptr_init.get ();
3669+ test_sptr_const ptr_orig{std::move (ptr_init)};
3670+ test_sptr ptr = oup::const_pointer_cast<test_object>(std::move (ptr_orig));
3671+
3672+ REQUIRE (instances == 1 );
3673+ REQUIRE (ptr_orig == nullptr );
3674+ REQUIRE (ptr.get () == raw_ptr);
3675+ }
3676+
3677+ REQUIRE (instances == 0 );
3678+ REQUIRE (mem_track.leaks () == 0u );
3679+ REQUIRE (mem_track.double_del () == 0u );
3680+ }
3681+
3682+ TEST_CASE (" const pointer cast sealed from null" , " [pointer_cast]" ) {
3683+ memory_tracker mem_track;
3684+
3685+ {
3686+ test_sptr_const ptr_orig;
3687+ test_sptr ptr = oup::const_pointer_cast<test_object>(std::move (ptr_orig));
3688+
3689+ REQUIRE (instances == 0 );
3690+ REQUIRE (ptr_orig == nullptr );
3691+ REQUIRE (ptr == nullptr );
3692+ }
3693+
3694+ REQUIRE (instances == 0 );
3695+ REQUIRE (mem_track.leaks () == 0u );
3696+ REQUIRE (mem_track.double_del () == 0u );
3697+ }
3698+
3699+ TEST_CASE (" const pointer cast observer copy from valid" , " [pointer_cast]" ) {
3700+ memory_tracker mem_track;
3701+
3702+ {
3703+ test_sptr ptr_owner = oup::make_observable_sealed<test_object>();
3704+ test_object* raw_ptr = ptr_owner.get ();
3705+ test_optr_const ptr_orig{ptr_owner};
3706+ test_optr ptr = oup::const_pointer_cast<test_object>(ptr_orig);
3707+
3708+ REQUIRE (instances == 1 );
3709+ REQUIRE (ptr_orig.get () == raw_ptr);
3710+ REQUIRE (ptr.get () == raw_ptr);
3711+ }
3712+
3713+ REQUIRE (instances == 0 );
3714+ REQUIRE (mem_track.leaks () == 0u );
3715+ REQUIRE (mem_track.double_del () == 0u );
3716+ }
3717+
3718+ TEST_CASE (" const pointer cast observer copy from null" , " [pointer_cast]" ) {
3719+ memory_tracker mem_track;
3720+
3721+ {
3722+ test_optr_const ptr_orig;
3723+ test_optr ptr = oup::const_pointer_cast<test_object>(ptr_orig);
3724+
3725+ REQUIRE (instances == 0 );
3726+ REQUIRE (ptr_orig == nullptr );
3727+ REQUIRE (ptr == nullptr );
3728+ }
3729+
3730+ REQUIRE (instances == 0 );
3731+ REQUIRE (mem_track.leaks () == 0u );
3732+ REQUIRE (mem_track.double_del () == 0u );
3733+ }
3734+
3735+ TEST_CASE (" const pointer cast observer move from valid" , " [pointer_cast]" ) {
3736+ memory_tracker mem_track;
3737+
3738+ {
3739+ test_sptr ptr_owner = oup::make_observable_sealed<test_object_derived>();
3740+ test_object* raw_ptr = ptr_owner.get ();
3741+ test_optr_const ptr_orig{ptr_owner};
3742+ test_optr ptr = oup::const_pointer_cast<test_object>(std::move (ptr_orig));
3743+
3744+ REQUIRE (instances == 1 );
3745+ REQUIRE (ptr_orig == nullptr );
3746+ REQUIRE (ptr.get () == raw_ptr);
3747+ }
3748+
3749+ REQUIRE (instances == 0 );
3750+ REQUIRE (mem_track.leaks () == 0u );
3751+ REQUIRE (mem_track.double_del () == 0u );
3752+ }
3753+
3754+ TEST_CASE (" const pointer cast observer move from null" , " [pointer_cast]" ) {
3755+ memory_tracker mem_track;
3756+
3757+ {
3758+ test_optr_const ptr_orig;
3759+ test_optr ptr = oup::const_pointer_cast<test_object>(std::move (ptr_orig));
3760+
3761+ REQUIRE (instances == 0 );
3762+ REQUIRE (ptr_orig == nullptr );
3763+ REQUIRE (ptr == nullptr );
3764+ }
3765+
3766+ REQUIRE (instances == 0 );
3767+ REQUIRE (mem_track.leaks () == 0u );
3768+ REQUIRE (mem_track.double_del () == 0u );
3769+ }
0 commit comments