diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-05 01:38:07 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-05-05 03:31:21 +0200 |
commit | 3f503fd32e456926f271b7d4bc485c91adc7b716 (patch) | |
tree | ed7d2f4c501f69fe3535181eb131d69abbeee651 /test | |
parent | 965e81a6bfc1d91041d2af32bf459a76d8c42fc8 (diff) |
Diffstat (limited to 'test')
-rw-r--r-- | test/bptr.cpp | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/test/bptr.cpp b/test/bptr.cpp index 55b10fe0..6050c4f5 100644 --- a/test/bptr.cpp +++ b/test/bptr.cpp @@ -1,6 +1,7 @@ #include "app.hpp" -#include "compat/assert.hpp" #include "compat/borrowed-ptr.inl" +#include "compat/assert.hpp" +#include "compat/defs.hpp" #include <array> namespace floormat { @@ -47,6 +48,8 @@ struct A int val, serial; explicit A(int val) : val{val}, serial{++A_total} { ++A_alive; } ~A() noexcept { --A_alive; fm_assert(A_alive >= 0); } + + fm_DECLARE_DELETED_COPY_MOVE_ASSIGNMENTS(A); }; void test1() @@ -277,10 +280,62 @@ void test7() check_empty(p1); check_empty(p2); fm_assert(A_total == 1 && A_alive == 0); +} +void test8() +{ A_total = 0; A_alive = 0; + + auto p1 = bptr<A>{InPlace, 81}; + auto p2 = bptr<A>{InPlace, 82}; + fm_assert(A_total == 2 && A_alive == 2); + + p1 = p2; + fm_assert(A_total == 2 && A_alive == 1); + + p2 = move(p1); + fm_assert(A_total == 2 && A_alive == 1); + + p1.reset(); + p2 = nullptr; + (void)p2; + fm_assert(A_total == 2 && A_alive == 0); } +void test9() +{ + A_total = 0; A_alive = 0; + + auto p1 = bptr<A>{InPlace, 9}; + auto p2 = p1; + p1 = p2; + fm_assert(p1.use_count() == 2); + fm_assert(A_total == 1); + fm_assert(A_alive == 1); + + p1.destroy(); + fm_assert(!p1); + fm_assert(!p2); + fm_assert(p1.use_count() == 0); + fm_assert(p2.use_count() == 0); + fm_assert(A_total == 1); + fm_assert(A_alive == 0); + + p1.swap(p2); + fm_assert(!p1 && !p2); + fm_assert(p1.use_count() == 0 && p2.use_count() == 0); + fm_assert(A_total == 1); + fm_assert(A_alive == 0); + + p1.reset(); + fm_assert(p1.use_count() == 0); + fm_assert(p2.use_count() == 0); + p2 = bptr<A>{(A*)nullptr}; + fm_assert(p1.use_count() == 0); + fm_assert(p2.use_count() == 0); + fm_assert(A_total == 1 && A_alive == 0); +}; + } // namespace void test_app::test_bptr() @@ -292,6 +347,8 @@ void test_app::test_bptr() test5(); test6(); test7(); + test8(); + test9(); } } // namespace floormat |