| 46 | }; |
| 47 | |
| 48 | TEST(ObjectPool, canCreateAndReuse) { |
| 49 | auto pool = Pool(); |
| 50 | ASSERT_EQ(0, pool.getCreatedObjectsCount()); |
| 51 | |
| 52 | Object* firstCreatedObject = nullptr; |
| 53 | Object* secondCreatedObject = nullptr; |
| 54 | |
| 55 | { |
| 56 | auto object = pool.create(); |
| 57 | ASSERT_EQ(1, pool.getCreatedObjectsCount()); |
| 58 | firstCreatedObject = object->get(); |
| 59 | auto object2 = pool.create(); |
| 60 | ASSERT_EQ(2, pool.getCreatedObjectsCount()); |
| 61 | secondCreatedObject = object2->get(); |
| 62 | } |
| 63 | |
| 64 | // Those objects should be reused |
| 65 | auto object = pool.create(); |
| 66 | ASSERT_EQ(2, pool.getCreatedObjectsCount()); |
| 67 | ASSERT_TRUE(object.get() != nullptr); |
| 68 | ASSERT_EQ(object->get(), secondCreatedObject); |
| 69 | |
| 70 | auto object2 = pool.create(); |
| 71 | ASSERT_EQ(2, pool.getCreatedObjectsCount()); |
| 72 | ASSERT_TRUE(object2.get() != nullptr); |
| 73 | ASSERT_EQ(object2->get(), firstCreatedObject); |
| 74 | } |
| 75 | |
| 76 | TEST(ObjectPool, cleanupOnRecycle) { |
| 77 | auto pool = Pool(); |
nothing calls this directly
no test coverage detected