From d995c693f3177f0c68cf0ac9f56e278861cd5125 Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 24 Dec 2023 12:54:43 +0800 Subject: [PATCH] Add unit tests for block_pool --- include/libpmr/synchronized_pool_resource.h | 2 +- test/pmr/test_pmr_block_pool.cpp | 26 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/libpmr/synchronized_pool_resource.h b/include/libpmr/synchronized_pool_resource.h index 8c54bf5d..578d494f 100644 --- a/include/libpmr/synchronized_pool_resource.h +++ b/include/libpmr/synchronized_pool_resource.h @@ -18,7 +18,7 @@ LIBPMR_NAMESPACE_BEG_ * \brief `synchronized_pool_resource` may be accessed from multiple threads without external synchronization, * and have thread-specific pools to reduce synchronization costs. * \note Unlike the standard library implementation, `synchronized_pool_resource` automatically manages - * the block size and reclaims all allocated memory to the central heap when the thread is destroyed, + * the block size and reclaims all deallocated memory to the central heap when the thread is destroyed, * rather than being destructed on its own. * \see https://en.cppreference.com/w/cpp/memory/synchronized_pool_resource */ diff --git a/test/pmr/test_pmr_block_pool.cpp b/test/pmr/test_pmr_block_pool.cpp index c354b440..5f666842 100644 --- a/test/pmr/test_pmr_block_pool.cpp +++ b/test/pmr/test_pmr_block_pool.cpp @@ -61,3 +61,29 @@ TEST(block_pool, central_cache_pool_ctor) { EXPECT_NE(b1, b4); } } + +TEST(block_pool, ctor) { + ASSERT_TRUE ((std::is_default_constructible>::value)); + ASSERT_FALSE((std::is_copy_constructible>::value)); + ASSERT_FALSE((std::is_move_constructible>::value)); + ASSERT_FALSE((std::is_copy_assignable>::value)); + ASSERT_FALSE((std::is_move_assignable>::value)); +} + +TEST(block_pool, allocate) { + std::vector v; + pmr::block_pool<1, 1> pool; + for (int i = 0; i < 100; ++i) { + v.push_back(pool.allocate()); + } + for (void *p: v) { + ASSERT_FALSE(nullptr == p); + pool.deallocate(p); + } + for (int i = 0; i < 100; ++i) { + ASSERT_EQ(v[v.size() - i - 1], pool.allocate()); + } + for (void *p: v) { + pool.deallocate(p); + } +}