From 61faa87c316bea320b2a94a4efbf82bff725a000 Mon Sep 17 00:00:00 2001 From: superp00t Date: Sun, 30 Mar 2025 23:36:05 -0400 Subject: [PATCH] feat(test): add tests for new allocation helpers --- test/Memory.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/Memory.cpp b/test/Memory.cpp index 8d78c83..a7ed316 100644 --- a/test/Memory.cpp +++ b/test/Memory.cpp @@ -1,6 +1,19 @@ #include "bc/Memory.hpp" #include "test/Test.hpp" +#include + +struct TestObject { + int m = 1; + TestObject() { + // printf("TestObject created\n"); + } + + ~TestObject() { + // printf("TestObject destroyed\n"); + } +}; + TEST_CASE("Blizzard::Memory::Allocate", "[memory]") { SECTION("allocates memory and returns pointer") { auto ptr = Blizzard::Memory::Allocate(100); @@ -18,3 +31,23 @@ TEST_CASE("Blizzard::Memory::Allocate", "[memory]") { 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; + } +}