Add some tests
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "memory.h"
|
||||
#include "assert/assert.h"
|
||||
#include "util/math.h"
|
||||
|
||||
void * memoryAllocate(const size_t size) {
|
||||
assertTrue(size > 0, "Cannot allocate 0 bytes of memory.");
|
||||
@@ -83,14 +84,13 @@ void memoryReallocate(void **ptr, const size_t size) {
|
||||
|
||||
void memoryResize(void **ptr, const size_t oldSize, const size_t newSize) {
|
||||
assertNotNull(ptr, "Cannot resize NULL pointer.");
|
||||
assertTrue(newSize > 0, "Cannot resize to 0 bytes of memory.");
|
||||
assertTrue(oldSize > 0, "Old size cannot be 0 bytes.");
|
||||
if(newSize == oldSize) return;
|
||||
if(oldSize == 0) return memoryReallocate(ptr, newSize);
|
||||
|
||||
assertTrue(newSize > oldSize, "New size must be greater than old size.");
|
||||
|
||||
void *newPointer = memoryAllocate(newSize);
|
||||
assertNotNull(newPointer, "Memory resizing failed.");
|
||||
memoryCopy(newPointer, *ptr, oldSize);
|
||||
memoryCopy(newPointer, *ptr, mathMin(oldSize, newSize));
|
||||
memoryFree(*ptr);
|
||||
*ptr = newPointer;
|
||||
}
|
||||
Reference in New Issue
Block a user