#include "test_main.h"
#include "stuff/allocate.h"
static void test_allocate(void)
{
void* p = allocate(0);
check_null("allocate(NULL)", p);
if (p)
free(p);
p = allocate(1);
check_nonnull("allocate(1)", p);
if (p)
free(p);
}
static void test_reallocate(void)
{
void* p = reallocate(NULL, 0);
check_null("reallocate(NULL, 0)", p);
p = reallocate(NULL, 1);
check_nonnull("reallocate(NULL, 1)", p);
p = reallocate(p, 2);
check_nonnull("reallocate(p, 2)", p);
p = reallocate(p, 0);
check_nonnull("reallocate(p, 0)", p);
if (p)
free(p);
}
static void test_savestr(void)
{
char* s = savestr("");
check_nonnull("savestr(\"\")", s);
if (s) {
check_string("savestr(\"\")", "", s);
free(s);
}
const char* cs = "A brilliant red Barchetta";
s = savestr(cs);
check_nonnull("savestr(cs)", s);
if (s) {
check_string("savestr(cs)", cs, s);
free(s);
}
}
static void test_makestr(void)
{
char* s = makestr(NULL);
check_nonnull("makestr(NULL)", s);
if (s) {
check_string("makestr(NULL)", "", s);
free(s);
}
s = makestr("", NULL);
check_nonnull("makestr(\"\", NULL)", s);
if (s) {
check_string("makestr(\"\", NULL)", "", s);
free(s);
}
s = makestr("A", " brilliant", " red", " Barchetta", NULL);
check_nonnull("makestr(a, b, c, d)", s);
if (s) {
check_string("makestr(a, b, c, d)", "A brilliant red Barchetta", s);
free(s);
}
}
static int test_main(void)
{
int err = 0;
if (!err) err = test_add("test allocate", test_allocate);
if (!err) err = test_add("test reallocate", test_reallocate);
if (!err) err = test_add("test savestr", test_savestr);
if (!err) err = test_add("test makestr", test_makestr);
return err;
}