mirror of
https://github.com/thunderbrewhq/common.git
synced 2025-12-12 03:02:29 +00:00
feat(memory): add assertion mode check to CDataAllocator
This commit is contained in:
parent
739adccafd
commit
d4ee19c6af
4 changed files with 76 additions and 4 deletions
39
test/DataAllocator.cpp
Normal file
39
test/DataAllocator.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include "common/DataAllocator.hpp"
|
||||
#include "test/Test.hpp"
|
||||
|
||||
struct TestContainer
|
||||
{
|
||||
uint32_t value[10];
|
||||
};
|
||||
|
||||
TEST_CASE("CDataAllocator::CDataAllocator", "[dataallocator]") {
|
||||
SECTION("constructs new data allocator") {
|
||||
CDataAllocator allocator(sizeof(TestContainer), 2);
|
||||
SUCCEED();
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("CDataAllocator::GetData", "[dataallocator]") {
|
||||
SECTION("get allocated objects") {
|
||||
CDataAllocator allocator(sizeof(TestContainer), 2);
|
||||
auto container = (TestContainer*)allocator.GetData(0, __FILE__, __LINE__);
|
||||
auto container2 = (TestContainer*)allocator.GetData(0, __FILE__, __LINE__);
|
||||
auto container3 = (TestContainer*)allocator.GetData(0, __FILE__, __LINE__);
|
||||
REQUIRE(container);
|
||||
REQUIRE(container2);
|
||||
REQUIRE(container3);
|
||||
REQUIRE(allocator.DataUsed() == 3);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("CDataAllocator::PutData", "[dataallocator]") {
|
||||
SECTION("return allocated objects") {
|
||||
CDataAllocator allocator(sizeof(TestContainer), 2);
|
||||
auto container = (TestContainer*)allocator.GetData(0, __FILE__, __LINE__);
|
||||
auto container2 = (TestContainer*)allocator.GetData(0, __FILE__, __LINE__);
|
||||
auto container3 = (TestContainer*)allocator.GetData(0, __FILE__, __LINE__);
|
||||
allocator.PutData(container, __FILE__, __LINE__);
|
||||
allocator.PutData(container3, __FILE__, __LINE__);
|
||||
REQUIRE(allocator.DataUsed() == 1);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue