aboutsummaryrefslogtreecommitdiffstats
path: root/test/rspamd_cxx_unit_utils.hxx
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2021-07-22 17:52:54 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2021-07-22 17:52:54 +0100
commitacaebca84fa1d81fd48fecf29ef9eb65f0707e5b (patch)
tree265a04fddb82a541821c42837ae398897fc867b6 /test/rspamd_cxx_unit_utils.hxx
parentfd044f4cf02a5cad4d023af5df375d1f124e31bd (diff)
downloadrspamd-acaebca84fa1d81fd48fecf29ef9eb65f0707e5b.tar.gz
rspamd-acaebca84fa1d81fd48fecf29ef9eb65f0707e5b.zip
[Minor] Add weak ptr counterpart
Diffstat (limited to 'test/rspamd_cxx_unit_utils.hxx')
-rw-r--r--test/rspamd_cxx_unit_utils.hxx79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/rspamd_cxx_unit_utils.hxx b/test/rspamd_cxx_unit_utils.hxx
index be5d193f4..47e6c889b 100644
--- a/test/rspamd_cxx_unit_utils.hxx
+++ b/test/rspamd_cxx_unit_utils.hxx
@@ -236,6 +236,85 @@ TEST_CASE("make_shared dtor") {
CHECK(t == true);
}
+TEST_CASE("shared_ptr dtor") {
+ bool t;
+
+ {
+ rspamd::local_shared_ptr<deleter_test> pi(new deleter_test{t});
+
+ CHECK((!pi ? false : true));
+ CHECK(!!pi);
+ CHECK(pi.get() != nullptr);
+ CHECK(pi.use_count() == 1);
+ CHECK(pi.unique());
+ CHECK(t == false);
+ }
+
+ CHECK(t == true);
+
+ {
+ rspamd::local_shared_ptr<deleter_test> pi(new deleter_test{t});
+
+ CHECK((!pi ? false : true));
+ CHECK(!!pi);
+ CHECK(pi.get() != nullptr);
+ CHECK(pi.use_count() == 1);
+ CHECK(pi.unique());
+ CHECK(t == false);
+
+ rspamd::local_shared_ptr<deleter_test> pi2(pi);
+ CHECK(pi2 == pi);
+ CHECK(pi.use_count() == 2);
+ pi.reset();
+ CHECK(!(pi2 == pi));
+ CHECK(pi2.use_count() == 1);
+ CHECK(t == false);
+
+ pi = pi2;
+ CHECK(pi2 == pi);
+ CHECK(pi.use_count() == 2);
+ CHECK(t == false);
+ }
+
+ CHECK(t == true);
+}
+
+TEST_CASE("weak_ptr") {
+ bool t;
+
+ {
+ rspamd::local_shared_ptr<deleter_test> pi(new deleter_test{t});
+
+ CHECK((!pi ? false : true));
+ CHECK(!!pi);
+ CHECK(pi.get() != nullptr);
+ CHECK(pi.use_count() == 1);
+ CHECK(pi.unique());
+ CHECK(t == false);
+
+ rspamd::local_weak_ptr<deleter_test> wp(pi);
+ CHECK(wp.lock().get() != nullptr);
+ CHECK(pi.use_count() == 1);
+ CHECK(wp.use_count() == 1);
+ pi.reset();
+ CHECK(pi.use_count() == 0);
+ CHECK(wp.use_count() == 0);
+ }
+
+ CHECK(t == true);
+
+ rspamd::local_weak_ptr<deleter_test> wp;
+ {
+ rspamd::local_shared_ptr<deleter_test> pi(new deleter_test{t});
+ wp = pi;
+ CHECK(!wp.expired());
+ CHECK(wp.lock().get() != nullptr);
+ }
+
+ CHECK(t == true);
+ CHECK(wp.expired());
+}
+
}
#endif