Skip to content

Commit

Permalink
Add unit tests for block_pool
Browse files Browse the repository at this point in the history
  • Loading branch information
mutouyun committed Dec 24, 2023
1 parent c10d84a commit d995c69
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/libpmr/synchronized_pool_resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
26 changes: 26 additions & 0 deletions test/pmr/test_pmr_block_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<pmr::block_pool<1, 1>>::value));
ASSERT_FALSE((std::is_copy_constructible<pmr::block_pool<1, 1>>::value));
ASSERT_FALSE((std::is_move_constructible<pmr::block_pool<1, 1>>::value));
ASSERT_FALSE((std::is_copy_assignable<pmr::block_pool<1, 1>>::value));
ASSERT_FALSE((std::is_move_assignable<pmr::block_pool<1, 1>>::value));
}

TEST(block_pool, allocate) {
std::vector<void *> 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);
}
}

0 comments on commit d995c69

Please sign in to comment.