New allocators, testing framework, overall improvements
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#include "malunal/allocators/stack.h"
|
||||
#include "malunal/microtest.h"
|
||||
|
||||
MICROTEST(stack_allocator, can_init_and_free) {
|
||||
error_t result = {};
|
||||
stack_allocator_t allocator = {};
|
||||
malunal_size_t temporary = 0;
|
||||
|
||||
result = stack_allocator_init(16, 8, null, &allocator);
|
||||
MICROTEST_ASSERT_NULL(result.domain);
|
||||
|
||||
result = stack_allocator_stride(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 16);
|
||||
|
||||
result = stack_allocator_count(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 0);
|
||||
|
||||
result = stack_allocator_capacity(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 8);
|
||||
|
||||
result = stack_allocator_free(&allocator);
|
||||
MICROTEST_ASSERT_NULL(result.domain);
|
||||
|
||||
result = stack_allocator_stride(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 0);
|
||||
|
||||
result = stack_allocator_count(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 0);
|
||||
|
||||
result = stack_allocator_capacity(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 0);
|
||||
}
|
||||
|
||||
MICROTEST(stack_allocator, can_acquire_and_dispose) {
|
||||
error_t result = {};
|
||||
stack_allocator_t allocator = {};
|
||||
malunal_mptr_t address = null;
|
||||
malunal_size_t temporary = 0;
|
||||
|
||||
stack_allocator_init(16, 8, null, &allocator);
|
||||
result = stack_allocator_acquire(&allocator, &address);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_ASSERT_NOT_NULL(address);
|
||||
|
||||
result = stack_allocator_count(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 1);
|
||||
|
||||
result = stack_allocator_dispose(&allocator, address);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
|
||||
result = stack_allocator_count(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user