feat(test): add tests for new allocation helpers

This commit is contained in:
phaneron 2025-03-30 23:36:05 -04:00
parent 4feaa132ab
commit 61faa87c31

View file

@ -1,6 +1,19 @@
#include "bc/Memory.hpp" #include "bc/Memory.hpp"
#include "test/Test.hpp" #include "test/Test.hpp"
#include <cstdio>
struct TestObject {
int m = 1;
TestObject() {
// printf("TestObject created\n");
}
~TestObject() {
// printf("TestObject destroyed\n");
}
};
TEST_CASE("Blizzard::Memory::Allocate", "[memory]") { TEST_CASE("Blizzard::Memory::Allocate", "[memory]") {
SECTION("allocates memory and returns pointer") { SECTION("allocates memory and returns pointer") {
auto ptr = Blizzard::Memory::Allocate(100); auto ptr = Blizzard::Memory::Allocate(100);
@ -18,3 +31,23 @@ TEST_CASE("Blizzard::Memory::Allocate", "[memory]") {
Blizzard::Memory::Free(ptr); Blizzard::Memory::Free(ptr);
} }
} }
TEST_CASE("helper macros", "[memory]") {
SECTION("ALLOCATE memory and return pointer") {
auto m = ALLOC(128);
REQUIRE(m);
FREE(m);
}
SECTION("NEW object and DELETE it") {
auto m = NEW(TestObject);
DEL(m);
}
}
TEST_CASE("operator new", "[memory]") {
SECTION("allocate memory through the new operator") {
auto m = new uint8_t[0xCAFE];
delete m;
}
}