Skip to content

Commit d995c69

Browse files
committed
Add unit tests for block_pool
1 parent c10d84a commit d995c69

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

include/libpmr/synchronized_pool_resource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LIBPMR_NAMESPACE_BEG_
1818
* \brief `synchronized_pool_resource` may be accessed from multiple threads without external synchronization,
1919
* and have thread-specific pools to reduce synchronization costs.
2020
* \note Unlike the standard library implementation, `synchronized_pool_resource` automatically manages
21-
* the block size and reclaims all allocated memory to the central heap when the thread is destroyed,
21+
* the block size and reclaims all deallocated memory to the central heap when the thread is destroyed,
2222
* rather than being destructed on its own.
2323
* \see https://en.cppreference.com/w/cpp/memory/synchronized_pool_resource
2424
*/

test/pmr/test_pmr_block_pool.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,29 @@ TEST(block_pool, central_cache_pool_ctor) {
6161
EXPECT_NE(b1, b4);
6262
}
6363
}
64+
65+
TEST(block_pool, ctor) {
66+
ASSERT_TRUE ((std::is_default_constructible<pmr::block_pool<1, 1>>::value));
67+
ASSERT_FALSE((std::is_copy_constructible<pmr::block_pool<1, 1>>::value));
68+
ASSERT_FALSE((std::is_move_constructible<pmr::block_pool<1, 1>>::value));
69+
ASSERT_FALSE((std::is_copy_assignable<pmr::block_pool<1, 1>>::value));
70+
ASSERT_FALSE((std::is_move_assignable<pmr::block_pool<1, 1>>::value));
71+
}
72+
73+
TEST(block_pool, allocate) {
74+
std::vector<void *> v;
75+
pmr::block_pool<1, 1> pool;
76+
for (int i = 0; i < 100; ++i) {
77+
v.push_back(pool.allocate());
78+
}
79+
for (void *p: v) {
80+
ASSERT_FALSE(nullptr == p);
81+
pool.deallocate(p);
82+
}
83+
for (int i = 0; i < 100; ++i) {
84+
ASSERT_EQ(v[v.size() - i - 1], pool.allocate());
85+
}
86+
for (void *p: v) {
87+
pool.deallocate(p);
88+
}
89+
}

0 commit comments

Comments
 (0)