Fixed more memory tests
This commit is contained in:
+10
-2
@@ -314,7 +314,7 @@ static void test_memoryCompare(void **state) {
|
||||
assert_int_equal(memoryCompare(b, b, size), 0);
|
||||
|
||||
// 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)
|
||||
// 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;
|
||||
void *ptr = memoryAllocate(initialSize);
|
||||
assert_non_null(ptr);
|
||||
assert_int_equal(memoryGetAllocatedCount(), 1);
|
||||
|
||||
// Initialize memory
|
||||
for(size_t i = 0; i < initialSize; i++) {
|
||||
@@ -376,11 +377,13 @@ static void test_memoryResize(void **state) {
|
||||
memoryResize(&ptr, initialSize, initialSize);
|
||||
assert_non_null(ptr);
|
||||
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;
|
||||
memoryResize(&ptr, initialSize, newSize);
|
||||
assert_non_null(ptr);
|
||||
assert_int_equal(memoryGetAllocatedCount(), 1);
|
||||
|
||||
// Check that old data is preserved
|
||||
for(size_t i = 0; i < initialSize; i++) {
|
||||
@@ -391,6 +394,7 @@ static void test_memoryResize(void **state) {
|
||||
size_t smallerSize = 16;
|
||||
memoryResize(&ptr, newSize, smallerSize);
|
||||
assert_non_null(ptr);
|
||||
assert_int_equal(memoryGetAllocatedCount(), 1);
|
||||
|
||||
// Check that data is still correct up to the smaller size
|
||||
for(size_t i = 0; i < smallerSize; i++) {
|
||||
@@ -399,15 +403,19 @@ static void test_memoryResize(void **state) {
|
||||
|
||||
// Cannot realloc to size 0
|
||||
expect_assert_failure(memoryResize(&ptr, smallerSize, 0));
|
||||
assert_int_equal(memoryGetAllocatedCount(), 1);
|
||||
|
||||
// Cannot take NULL
|
||||
expect_assert_failure(memoryResize(NULL, smallerSize, 16));
|
||||
assert_int_equal(memoryGetAllocatedCount(), 1);
|
||||
|
||||
// memoryResize with oldsize of 0 not possible
|
||||
expect_assert_failure(memoryResize(&ptr, 0, 16));
|
||||
assert_int_equal(memoryGetAllocatedCount(), 1);
|
||||
|
||||
// Cannot resize more memory than possible
|
||||
expect_assert_failure(memoryResize(&ptr, smallerSize, SIZE_MAX));
|
||||
assert_int_equal(memoryGetAllocatedCount(), 1);
|
||||
|
||||
memoryFree(ptr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user