| 16 | }; |
| 17 | |
| 18 | UNIT_TEST(RefCounted_Smoke) |
| 19 | { |
| 20 | { |
| 21 | RefCountPtr<Resource> p; |
| 22 | } |
| 23 | |
| 24 | { |
| 25 | bool destroyed; |
| 26 | { |
| 27 | RefCountPtr<Resource> p(new Resource(destroyed)); |
| 28 | TEST_EQUAL(1, p->NumRefs(), ()); |
| 29 | TEST(!destroyed, ()); |
| 30 | } |
| 31 | TEST(destroyed, ()); |
| 32 | } |
| 33 | |
| 34 | { |
| 35 | bool destroyed; |
| 36 | { |
| 37 | RefCountPtr<Resource> a(new Resource(destroyed)); |
| 38 | TEST_EQUAL(1, a->NumRefs(), ()); |
| 39 | TEST(!destroyed, ()); |
| 40 | |
| 41 | RefCountPtr<Resource> b(a); |
| 42 | TEST(a.Get() == b.Get(), ()); |
| 43 | TEST_EQUAL(2, a->NumRefs(), ()); |
| 44 | TEST(!destroyed, ()); |
| 45 | |
| 46 | { |
| 47 | RefCountPtr<Resource> c; |
| 48 | TEST(c.Get() == nullptr, ()); |
| 49 | |
| 50 | c = b; |
| 51 | TEST(a.Get() == b.Get(), ()); |
| 52 | TEST(b.Get() == c.Get(), ()); |
| 53 | TEST_EQUAL(3, a->NumRefs(), ()); |
| 54 | TEST(!destroyed, ()); |
| 55 | } |
| 56 | |
| 57 | TEST(a.Get() == b.Get(), ()); |
| 58 | TEST_EQUAL(2, a->NumRefs(), ()); |
| 59 | TEST(!destroyed, ()); |
| 60 | |
| 61 | RefCountPtr<Resource> d(std::move(b)); |
| 62 | TEST(b.Get() == nullptr, ()); |
| 63 | TEST(a.Get() == d.Get(), ()); |
| 64 | TEST_EQUAL(2, a->NumRefs(), ()); |
| 65 | TEST(!destroyed, ()); |
| 66 | |
| 67 | #ifdef __clang__ |
| 68 | #pragma clang diagnostic push |
| 69 | #pragma clang diagnostic ignored "-Wself-assign-overloaded" |
| 70 | #endif // #ifdef __clang__ |
| 71 | a = a; |
| 72 | #ifdef __clang__ |
| 73 | #pragma clang diagnostic pop |
| 74 | #endif // #ifdef __clang__ |
| 75 | |