1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include "../src/util.h"
void TestReallocAndAppend(void);
void TestReallocAndAppend(void) {
size_t len = 0;
char *buf = NULL;
buf = ReallocAndAppend(buf, &len, "Hello %s", "World");
assert(buf != NULL);
assert(strcmp(buf, "Hello World") == 0);
char *new_buf = ReallocAndAppend(buf, &len, ", %s!", "User");
assert(new_buf != NULL);
assert(strcmp(new_buf, "Hello World, User!") == 0);
assert(ReallocAndAppend(NULL, NULL, "test") == NULL);
assert(ReallocAndAppend(buf, &len, NULL) == NULL);
free(new_buf);
}
int main(void) {
TestReallocAndAppend();
return 0;
}
|