Fixed more memory tests

This commit is contained in:
2026-04-13 22:55:59 -05:00
parent 650645eaff
commit 378227c377
+10 -2
View File
@@ -314,7 +314,7 @@ static void test_memoryCompare(void **state) {
assert_int_equal(memoryCompare(b, b, size), 0); assert_int_equal(memoryCompare(b, b, size), 0);
// Comparison of 0 bytes is always true // Comparison of 0 bytes is always true
assert_true(memoryCompare(a, b, 0)); assert_int_equal(memoryCompare(a, b, 0), 0);
// Compare different sizes (should assert, so we only test the API contract) // Compare different sizes (should assert, so we only test the API contract)
// Not possible with current API, as size is explicit, but document intent. // Not possible with current API, as size is explicit, but document intent.
@@ -365,6 +365,7 @@ static void test_memoryResize(void **state) {
size_t initialSize = 32; size_t initialSize = 32;
void *ptr = memoryAllocate(initialSize); void *ptr = memoryAllocate(initialSize);
assert_non_null(ptr); assert_non_null(ptr);
assert_int_equal(memoryGetAllocatedCount(), 1);
// Initialize memory // Initialize memory
for(size_t i = 0; i < initialSize; i++) { for(size_t i = 0; i < initialSize; i++) {
@@ -376,11 +377,13 @@ static void test_memoryResize(void **state) {
memoryResize(&ptr, initialSize, initialSize); memoryResize(&ptr, initialSize, initialSize);
assert_non_null(ptr); assert_non_null(ptr);
assert_ptr_equal(ptr, oldPtr); assert_ptr_equal(ptr, oldPtr);
assert_int_equal(memoryGetAllocatedCount(), 1);
// Reallocate to a larger size // Reallocate to a larger size, it should not leak.
size_t newSize = 64; size_t newSize = 64;
memoryResize(&ptr, initialSize, newSize); memoryResize(&ptr, initialSize, newSize);
assert_non_null(ptr); assert_non_null(ptr);
assert_int_equal(memoryGetAllocatedCount(), 1);
// Check that old data is preserved // Check that old data is preserved
for(size_t i = 0; i < initialSize; i++) { for(size_t i = 0; i < initialSize; i++) {
@@ -391,6 +394,7 @@ static void test_memoryResize(void **state) {
size_t smallerSize = 16; size_t smallerSize = 16;
memoryResize(&ptr, newSize, smallerSize); memoryResize(&ptr, newSize, smallerSize);
assert_non_null(ptr); assert_non_null(ptr);
assert_int_equal(memoryGetAllocatedCount(), 1);
// Check that data is still correct up to the smaller size // Check that data is still correct up to the smaller size
for(size_t i = 0; i < smallerSize; i++) { for(size_t i = 0; i < smallerSize; i++) {
@@ -399,15 +403,19 @@ static void test_memoryResize(void **state) {
// Cannot realloc to size 0 // Cannot realloc to size 0
expect_assert_failure(memoryResize(&ptr, smallerSize, 0)); expect_assert_failure(memoryResize(&ptr, smallerSize, 0));
assert_int_equal(memoryGetAllocatedCount(), 1);
// Cannot take NULL // Cannot take NULL
expect_assert_failure(memoryResize(NULL, smallerSize, 16)); expect_assert_failure(memoryResize(NULL, smallerSize, 16));
assert_int_equal(memoryGetAllocatedCount(), 1);
// memoryResize with oldsize of 0 not possible // memoryResize with oldsize of 0 not possible
expect_assert_failure(memoryResize(&ptr, 0, 16)); expect_assert_failure(memoryResize(&ptr, 0, 16));
assert_int_equal(memoryGetAllocatedCount(), 1);
// Cannot resize more memory than possible // Cannot resize more memory than possible
expect_assert_failure(memoryResize(&ptr, smallerSize, SIZE_MAX)); expect_assert_failure(memoryResize(&ptr, smallerSize, SIZE_MAX));
assert_int_equal(memoryGetAllocatedCount(), 1);
memoryFree(ptr); memoryFree(ptr);