mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 16:56:45 +08:00
Add unit tests for block_pool
This commit is contained in:
parent
c10d84a8f2
commit
d995c693f3
@ -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
|
||||
*/
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user