Skip to content

Commit acf661c

Browse files
committed
Added enable_observer_from_this test with object on heap
1 parent b44f93d commit acf661c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/runtime_tests.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3221,3 +3221,27 @@ TEST_CASE("observer from this stack", "[observer_from_this]") {
32213221
REQUIRE(mem_track.leaks() == 0u);
32223222
REQUIRE(mem_track.double_del() == 0u);
32233223
}
3224+
3225+
TEST_CASE("observer from this heap", "[observer_from_this]") {
3226+
memory_tracker mem_track;
3227+
3228+
{
3229+
test_object_observer_from_this* obj = new test_object_observer_from_this;
3230+
const test_object_observer_from_this* cobj = obj;
3231+
3232+
test_optr_from_this optr_from_this = obj->observer_from_this();
3233+
test_optr_from_this_const optr_from_this_const = cobj->observer_from_this();
3234+
3235+
REQUIRE(instances == 1);
3236+
REQUIRE(optr_from_this.expired() == true);
3237+
REQUIRE(optr_from_this_const.expired() == true);
3238+
REQUIRE(optr_from_this.get() == nullptr);
3239+
REQUIRE(optr_from_this_const.get() == nullptr);
3240+
3241+
delete obj;
3242+
}
3243+
3244+
REQUIRE(instances == 0);
3245+
REQUIRE(mem_track.leaks() == 0u);
3246+
REQUIRE(mem_track.double_del() == 0u);
3247+
}

0 commit comments

Comments
 (0)