diff --git a/pool.hpp b/pool.hpp index 0ca890c0..aca6209b 100644 --- a/pool.hpp +++ b/pool.hpp @@ -144,6 +144,7 @@ namespace cruft { auto capacity (void) const { return m_capacity; } auto size (void) const { return m_size.load (); } bool empty (void) const { return size () == 0; } + bool full (void) const { return size () == capacity (); } // Indexing diff --git a/test/pool.cpp b/test/pool.cpp index e2979f45..56b14cef 100644 --- a/test/pool.cpp +++ b/test/pool.cpp @@ -28,7 +28,7 @@ check_unique_ptr (cruft::TAP::logger &tap) std::set uintset; // Take all pointers out, checking they are unique, then replace for destruction. - while (!uintpool.empty ()) + while (!uintpool.full ()) uintset.insert (uintpool.allocate ()); tap.expect_eq (uintset.size (), uintpool.capacity (), "extracted maximum elements"); @@ -40,7 +40,7 @@ check_unique_ptr (cruft::TAP::logger &tap) uintset.clear (); // Do the above one more time to ensure that releasing works right - while (!uintpool.empty ()) + while (!uintpool.full ()) uintset.insert (uintpool.allocate ()); tap.expect_eq (uintset.size (), uintpool.capacity (), "re-extracted maximum elements"); } @@ -120,6 +120,24 @@ done: } +//----------------------------------------------------------------------------- +void +check_size_queries (cruft::TAP::logger &tap) +{ + cruft::pool data (8); + + tap.expect_eq (data.size (), 0u, "initial size is zero"); + tap.expect (data.empty (), "initial object is empty"); + + auto first = data.allocate (); + tap.expect_eq (data.size (), 1u, "1 allocation has size of 1"); + tap.expect (!data.empty (), "1 allocation is not empty"); + + data.deallocate (first); + tap.expect (data.empty (), "full deallocation is empty"); +} + + //----------------------------------------------------------------------------- int main (int, char **) @@ -129,5 +147,6 @@ main (int, char **) check_unique_ptr (tap); check_keep_value (tap); check_keep_variadic_value (tap); + check_size_queries (tap); }); }