Files
allocators/tests/pool_allocator.c
T

62 lines
1.9 KiB
C

#include "malunal/allocators/pool.h"
#include "malunal/microtest.h"
MICROTEST(pool_allocator, can_init_and_free) {
error_t result = {};
pool_allocator_t allocator = {};
malunal_size_t temporary = 0;
result = pool_allocator_init(16, 8, null, &allocator);
MICROTEST_ASSERT_NULL(result.domain);
result = pool_allocator_stride(&allocator, &temporary);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_EXPECT_EQ(temporary, 16);
result = pool_allocator_count(&allocator, &temporary);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_EXPECT_EQ(temporary, 0);
result = pool_allocator_capacity(&allocator, &temporary);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_EXPECT_EQ(temporary, 8);
result = pool_allocator_free(&allocator);
MICROTEST_ASSERT_NULL(result.domain);
result = pool_allocator_stride(&allocator, &temporary);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_EXPECT_EQ(temporary, 0);
result = pool_allocator_count(&allocator, &temporary);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_EXPECT_EQ(temporary, 0);
result = pool_allocator_capacity(&allocator, &temporary);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_EXPECT_EQ(temporary, 0);
}
MICROTEST(pool_allocator, can_acquire_and_dispose) {
error_t result = {};
pool_allocator_t allocator = {};
malunal_mptr_t address = null;
malunal_size_t temporary = 0;
pool_allocator_init(16, 8, null, &allocator);
result = pool_allocator_acquire(&allocator, &address);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_ASSERT_NOT_NULL(address);
result = pool_allocator_count(&allocator, &temporary);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_EXPECT_EQ(temporary, 1);
result = pool_allocator_dispose(&allocator, address);
MICROTEST_EXPECT_NULL(result.domain);
result = pool_allocator_count(&allocator, &temporary);
MICROTEST_EXPECT_NULL(result.domain);
MICROTEST_EXPECT_EQ(temporary, 0);
}