| 6 | #include "fl/stl/vector.h" |
| 7 | |
| 8 | FL_TEST_FILE(FL_FILEPATH) { |
| 9 | |
| 10 | namespace shared_ptr_test { |
| 11 | |
| 12 | // Test class that does NOT inherit from fl::Referent (non-intrusive) |
| 13 | class TestClass { |
| 14 | public: |
| 15 | TestClass() : mValue(0), mDestructorCalled(nullptr) {} |
| 16 | TestClass(int value) : mValue(value), mDestructorCalled(nullptr) {} |
| 17 | TestClass(int a, int b) : mValue(a + b), mDestructorCalled(nullptr) {} |
| 18 | |
| 19 | // Constructor that allows tracking destructor calls |
| 20 | TestClass(int value, bool* destructor_flag) : mValue(value), mDestructorCalled(destructor_flag) {} |
| 21 | |
| 22 | ~TestClass() { |
| 23 | if (mDestructorCalled) { |
| 24 | *mDestructorCalled = true; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | int getValue() const { return mValue; } |
| 29 | void setValue(int value) { mValue = value; } |
| 30 | |
| 31 | private: |
| 32 | int mValue; |
| 33 | bool* mDestructorCalled; |
| 34 | }; |
| 35 | |
| 36 | // Derived class for testing polymorphism |
| 37 | class DerivedTestClass : public TestClass { |
| 38 | public: |
| 39 | DerivedTestClass() : TestClass(), mExtraValue(0) {} |
| 40 | DerivedTestClass(int value, int extra) : TestClass(value), mExtraValue(extra) {} |
| 41 | |
| 42 | int getExtraValue() const { return mExtraValue; } |
| 43 | |
| 44 | private: |
| 45 | int mExtraValue; |
| 46 | }; |
| 47 | |
| 48 | // Custom deleter for testing |
| 49 | struct CustomDeleter { |
| 50 | mutable fl::shared_ptr<bool> called_flag; |
| 51 | |
| 52 | CustomDeleter() : called_flag(fl::make_shared<bool>(false)) {} |
| 53 | |
| 54 | void operator()(TestClass* ptr) const { |
| 55 | *called_flag = true; |
| 56 | delete ptr; // ok bare allocation |
| 57 | } |
| 58 | |
| 59 | bool called() const { return *called_flag; } |
| 60 | }; |
| 61 | |
| 62 | FL_TEST_CASE("fl::shared_ptr default construction") { |
| 63 | fl::shared_ptr<TestClass> ptr; |
| 64 | FL_CHECK(!ptr); |
| 65 | FL_CHECK_EQ(ptr.get(), nullptr); |
nothing calls this directly
no test coverage detected