5 #include <rive/refcnt.hpp>
11 class MyRefCnt : public RefCnt {
15 void require_count(int value) { REQUIRE(this->debugging_refcnt() == value); }
18 TEST_CASE("refcnt", "[basics]") {
20 REQUIRE(my.debugging_refcnt() == 1);
22 REQUIRE(my.debugging_refcnt() == 2);
24 REQUIRE(my.debugging_refcnt() == 1);
27 REQUIRE(my.debugging_refcnt() == 2);
29 REQUIRE(my.debugging_refcnt() == 1);
31 // just exercise these to be sure they don't crash
32 safe_ref((MyRefCnt*)nullptr);
33 safe_unref((MyRefCnt*)nullptr);
36 TEST_CASE("rcp", "[basics]") {
37 rcp<MyRefCnt> r0(nullptr);
39 REQUIRE(r0.get() == nullptr);
42 rcp<MyRefCnt> r1(new MyRefCnt);
43 REQUIRE(r1.get() != nullptr);
46 REQUIRE(r1->debugging_refcnt() == 1);
49 REQUIRE(r1.get() == r2.get());
51 REQUIRE(r2->debugging_refcnt() == 2);
53 auto ptr = r2.release();
54 REQUIRE(r2.get() == nullptr);
55 REQUIRE(r1.get() == ptr);
57 // This is important, calling release() does not modify the ref count on the object
58 // We have to manage that explicit since we called release()
59 REQUIRE(r1->debugging_refcnt() == 2);
61 REQUIRE(r1->debugging_refcnt() == 1);
64 REQUIRE(r1.get() == nullptr);