Added memory checks
Some checks failed
Build Dusk / run-tests (push) Successful in 2m6s
Build Dusk / build-linux (push) Successful in 2m6s
Build Dusk / build-psp (push) Failing after 1m47s

This commit is contained in:
2026-01-06 11:02:26 -06:00
parent af5bf987c8
commit 0df7845f2c
19 changed files with 640 additions and 13 deletions

View File

@@ -11,31 +11,64 @@
static void test_memoryAllocate(void **state) {
(void)state;
size_t size = 128;
void *ptr = memoryAllocate(size);
// Memory should allocate
void *ptr = memoryAllocate(128);
assert_non_null(ptr);
// Allocating should be tracked
assert_int_equal(memoryGetAllocatedCount(), 1);
void *ptr2 = memoryAllocate(256);
assert_non_null(ptr2);
assert_int_equal(memoryGetAllocatedCount(), 2);
// Free memory
memoryFree(ptr);
assert_int_equal(memoryGetAllocatedCount(), 1);
memoryFree(ptr2);
assert_int_equal(memoryGetAllocatedCount(), 0);
// Should not be able to allocate 0 bytes
expect_assert_failure(memoryAllocate(0));
// Should not be able to allocate more memory than possible
expect_assert_failure(memoryAllocate(SIZE_MAX));
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memoryFree(void **state) {
(void)state;
// Create some memory
size_t size = 64;
void *ptr = memoryAllocate(size);
void *ptr = memoryAllocate(64);
assert_non_null(ptr);
assert_int_equal(memoryGetAllocatedCount(), 1);
// Free
memoryFree(ptr);
// Allocated count should decrease
assert_int_equal(memoryGetAllocatedCount(), 0);
ptr = memoryAllocate(32);
assert_non_null(ptr);
void *ptr2 = memoryAllocate(32);
assert_non_null(ptr2);
assert_int_equal(memoryGetAllocatedCount(), 2);
// Free both
memoryFree(ptr);
assert_int_equal(memoryGetAllocatedCount(), 1);
memoryFree(ptr2);
assert_int_equal(memoryGetAllocatedCount(), 0);
// Expect unable to free NULL
expect_assert_failure(memoryFree(NULL));
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memoryCopy(void **state) {
@@ -73,6 +106,9 @@ static void test_memoryCopy(void **state) {
memoryFree(src);
memoryFree(dest);
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memorySet(void **state) {
@@ -104,6 +140,9 @@ static void test_memorySet(void **state) {
}
memoryFree(ptr);
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memoryZero(void **state) {
@@ -129,6 +168,9 @@ static void test_memoryZero(void **state) {
expect_assert_failure(memoryZero(ptr, 0));
memoryFree(ptr);
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memoryCopyRangeSafe(void **state) {
@@ -175,6 +217,9 @@ static void test_memoryCopyRangeSafe(void **state) {
memoryFree(src);
memoryFree(dest);
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memoryMove(void **state) {
@@ -225,6 +270,9 @@ static void test_memoryMove(void **state) {
expect_assert_failure(memoryMove(ptr, ptr, size));
memoryFree(ptr);
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memoryCompare(void **state) {
@@ -273,6 +321,9 @@ static void test_memoryCompare(void **state) {
memoryFree(a);
memoryFree(b);
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memoryReallocate(void **state) {
@@ -303,6 +354,9 @@ static void test_memoryReallocate(void **state) {
// All we really care about is that the pointer is valid after reallocations
memoryFree(ptr);
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
static void test_memoryResize(void **state) {
@@ -356,6 +410,9 @@ static void test_memoryResize(void **state) {
expect_assert_failure(memoryResize(&ptr, smallerSize, SIZE_MAX));
memoryFree(ptr);
// Expect no leaks
assert_int_equal(memoryGetAllocatedCount(), 0);
}
int main(int argc, char **argv) {