#include "assert.h"
#include "util.h"
#include <string.h>
#define _ASSERT_FUNC_FAIL(...) test_fail(func, file, line, 1, __VA_ARGS__)
void _assert_null (_ASSERT_FUNC_ARGS, const void *ptr)
{
if (ptr)
_ASSERT_FUNC_FAIL("%p != NULL", ptr);
}
void _assert_strcmp (_ASSERT_FUNC_ARGS, const char *is, const char *should_be)
{
if (!should_be && !is)
return;
if (!is || strcmp(is, should_be))
_ASSERT_FUNC_FAIL("%s != %s", dump_str(is), dump_str(should_be));
}
void _assert_strncmp (_ASSERT_FUNC_ARGS, const char *is, const char *should_be, size_t n)
{
if (!should_be && !is)
return;
if (!is || strncmp(is, should_be, n))
_ASSERT_FUNC_FAIL("%s:%u != %s", dump_strn(is, n), (unsigned) n, dump_strn(should_be, n));
}
void _assert_strlen (_ASSERT_FUNC_ARGS, const char *str, size_t n)
{
if (!str || strlen(str) != n)
_ASSERT_FUNC_FAIL("strlen(%s) != %u", dump_str(str), (unsigned) n);
}
void _assert_strnull (_ASSERT_FUNC_ARGS, const char *str)
{
if (str)
_ASSERT_FUNC_FAIL("%s != NULL", dump_str(str));
}
void _assert_memcmp(_ASSERT_FUNC_ARGS, const char *is, const char *should_be, size_t len)
{
if (!should_be && !is)
return;
if (!is || memcmp(is, should_be, len))
_ASSERT_FUNC_FAIL("%s:%zu != %s", dump_strn(is, len), len, dump_strn(should_be, len));
}
void _assert_success (_ASSERT_FUNC_ARGS, err_t err)
{
if (err)
_ASSERT_FUNC_FAIL("err: %s", dump_str(error_name(err)));
}
void _assert_err (_ASSERT_FUNC_ARGS, err_t is, err_t should_be)
{
if (is != should_be)
_ASSERT_FUNC_FAIL("err: %s != %s", dump_str(error_name(is)), dump_str(error_name(should_be)));
}
void _assert_error (_ASSERT_FUNC_ARGS, const error_t *is, const error_t *should_be)
{
if (!error_cmp_eq(is, should_be))
_ASSERT_FUNC_FAIL("error: %s != %s", dump_str(error_msg(is)), dump_str(error_msg(should_be)));
}