Files
test2/source/blender/blenlib/tests/BLI_pool_test.cc
Campbell Barton 3f8cd44485 Cleanup: move BLI_strict_flags.h last, not that it should be kept last
Also add a note in the header why it should be kept last.
2024-02-14 13:40:31 +11:00

56 lines
961 B
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: Apache-2.0 */
#include "testing/testing.h"
#include "BLI_exception_safety_test_utils.hh"
#include "BLI_pool.hh"
#include "BLI_strict_flags.h" /* Keep last. */
namespace blender::tests {
TEST(pool, DefaultConstructor)
{
Pool<int> pool;
EXPECT_EQ(pool.size(), 0);
}
TEST(pool, Allocation)
{
Vector<int *> ptrs;
Pool<int> pool;
for (int i = 0; i < 100; i++) {
ptrs.append(&pool.construct(i));
}
EXPECT_EQ(pool.size(), 100);
for (int *ptr : ptrs) {
pool.destruct(*ptr);
}
EXPECT_EQ(pool.size(), 0);
}
TEST(pool, Reuse)
{
Vector<int *> ptrs;
Pool<int> pool;
for (int i = 0; i < 32; i++) {
ptrs.append(&pool.construct(i));
}
int *freed_ptr = ptrs[6];
pool.destruct(*freed_ptr);
ptrs[6] = &pool.construct(0);
EXPECT_EQ(ptrs[6], freed_ptr);
for (int *ptr : ptrs) {
pool.destruct(*ptr);
}
}
} // namespace blender::tests