New allocators, testing framework, overall improvements
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#include "malunal/allocators/linear.h"
|
||||
#include "malunal/microtest.h"
|
||||
|
||||
MICROTEST(linear_allocator, can_init) {
|
||||
error_t result = {};
|
||||
linear_allocator_t allocator = {};
|
||||
malunal_mptr_t address = null;
|
||||
malunal_uint32_t temporary = 0;
|
||||
|
||||
allocator_acquire(libc_allocator(), 128, &address);
|
||||
result = linear_allocator_init(128, address, &allocator);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
|
||||
result = linear_allocator_size(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 128);
|
||||
|
||||
result = linear_allocator_used(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 0);
|
||||
}
|
||||
|
||||
MICROTEST(linear_allocator, can_acquire_and_dispose) {
|
||||
error_t result = {};
|
||||
linear_allocator_t allocator = {};
|
||||
malunal_mptr_t original = null;
|
||||
malunal_mptr_t address = null;
|
||||
malunal_uint32_t temporary = 0;
|
||||
|
||||
allocator_acquire(libc_allocator(), 128, &original);
|
||||
linear_allocator_init(128, original, &allocator);
|
||||
result = linear_allocator_acquire(&allocator, 64, &address);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_ASSERT_NOT_NULL(address);
|
||||
|
||||
result = linear_allocator_used(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 64);
|
||||
|
||||
result = linear_allocator_dispose(&allocator, address, 64);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
|
||||
result = linear_allocator_used(&allocator, &temporary);
|
||||
MICROTEST_EXPECT_NULL(result.domain);
|
||||
MICROTEST_EXPECT_EQ(temporary, 64);
|
||||
allocator_dispose(libc_allocator(), original, 128);
|
||||
}
|
||||
Reference in New Issue
Block a user