7 #include <throwing/shared_ptr.hpp> 12 A(
bool &deleted) : deleted_(deleted) {}
13 virtual ~A() { deleted_ =
true; }
14 A &operator=(
const A &) {
return *
this; }
22 B(
bool &deleted) : A(deleted) {}
23 B &operator=(
const B &) {
return *
this; }
24 int dummy() {
return dummy_b; }
28 TEST_CASE(
"shared_ptr reset with no arguments clears",
"[shared_ptr][reset]") {
30 A *ptr1 =
new A(deleted);
31 throwing::shared_ptr<A> t_ptr1(ptr1);
32 REQUIRE(t_ptr1.get() == ptr1);
33 REQUIRE_FALSE(deleted);
35 REQUIRE(t_ptr1.get() ==
nullptr);
39 TEST_CASE(
"shared_ptr reset with pointer",
"[shared_ptr][reset]") {
40 bool deleted1 =
false;
41 A *ptr1 =
new A(deleted1);
42 bool deleted2 =
false;
43 B *ptr2 =
new B(deleted2);
45 throwing::shared_ptr<A> t_ptr1(ptr1);
46 REQUIRE(t_ptr1.get() == ptr1);
47 REQUIRE_FALSE(deleted1);
49 REQUIRE(t_ptr1.get() == ptr2);
53 TEST_CASE(
"shared_ptr reset with pointer and deleter",
"[shared_ptr][reset]") {
54 bool deleted1 =
false;
55 A *ptr1 =
new A(deleted1);
56 bool deleted2 =
false;
57 B *ptr2 =
new B(deleted2);
59 bool lamda_called =
false;
60 auto deleter = [&lamda_called](A *p) {
65 throwing::shared_ptr<A> t_ptr1(ptr1);
66 REQUIRE(t_ptr1.get() == ptr1);
67 REQUIRE_FALSE(deleted1);
69 t_ptr1.reset(ptr2, deleter);
70 REQUIRE_FALSE(lamda_called);
72 REQUIRE(t_ptr1.get() == ptr2);
76 REQUIRE(lamda_called);
77 REQUIRE(t_ptr1.get() ==
nullptr);
80 TEST_CASE(
"shared_ptr reset with pointer, deleter and allocator",
81 "[shared_ptr][reset]") {
82 bool deleted1 =
false;
83 A *ptr1 =
new A(deleted1);
84 bool deleted2 =
false;
85 B *ptr2 =
new B(deleted2);
87 bool lamda_called =
false;
88 auto deleter = [&lamda_called](A *p) {
93 throwing::shared_ptr<A> t_ptr1(ptr1);
94 REQUIRE(t_ptr1.get() == ptr1);
95 REQUIRE_FALSE(deleted1);
97 std::allocator<
void *> allocator;
98 t_ptr1.reset(ptr2, deleter, allocator);
99 REQUIRE_FALSE(lamda_called);
101 REQUIRE(t_ptr1.get() == ptr2);
105 REQUIRE(lamda_called);
106 REQUIRE(t_ptr1.get() ==
nullptr);
TEST_CASE("unique_ptr to array reset to convertible", "[unique_ptr][array][reset][conv.qual]")