terom@168: #ifndef TEST_ASSERT_H terom@168: #define TEST_ASSERT_H terom@168: terom@168: /** terom@168: * @file terom@168: * terom@168: * Various general assert-condition tests used to fail tests terom@168: */ terom@194: #include "fail.h" terom@168: #include "../error.h" terom@168: terom@168: /* terom@168: * Also accept the existance of the system assert() function terom@168: */ terom@168: #include terom@194: terom@194: /* terom@194: * Internal shorthand macros for passing func/file/line args terom@194: */ terom@194: #define _ASSERT_FUNC_ARGS const char *func, const char *file, int line terom@194: #define _ASSERT_FUNC_CALL(func, ...) func(__func__, __FILE__, __LINE__, __VA_ARGS__) terom@168: terom@168: /** terom@168: * Assert that the given condition is true, and fail with the given error if not terom@168: */ terom@194: #define assert_true(cond, ...) fail_if(cond, __VA_ARGS__) terom@194: terom@194: /** terom@194: * Assert failure unconditionally terom@194: */ terom@194: #define assert_fail(...) fail(__VA_ARGS__) terom@168: terom@168: /** terom@168: * Assert that the given pointer value is NULL. terom@168: */ terom@194: #define assert_null(ptr) _ASSERT_FUNC_CALL(_assert_null, ptr) terom@194: void _assert_null (_ASSERT_FUNC_ARGS, const void *ptr); terom@168: terom@168: /** terom@168: * Assert that the given NUL-terminated string matches the given target string exactly. terom@168: */ terom@194: #define assert_strcmp(is, should_be) _ASSERT_FUNC_CALL(_assert_strcmp, is, should_be) terom@194: void _assert_strcmp (_ASSERT_FUNC_ARGS, const char *is, const char *should_be); terom@168: terom@168: /** terom@168: * Assert that the first \a n chars of the first string matches the second string exactly. terom@168: */ terom@194: #define assert_strncmp(is, should_be, n) _ASSERT_FUNC_CALL(_assert_strncmp, is, should_be, n) terom@194: void _assert_strncmp (_ASSERT_FUNC_ARGS, const char *is, const char *should_be, size_t n); terom@168: terom@168: /** terom@168: * Assert that the given \a str is \a n chars long. terom@168: */ terom@194: #define assert_strlen(str, n) _ASSERT_FUNC_CALL(_assert_strlen, str, n) terom@194: void _assert_strlen (_ASSERT_FUNC_ARGS, const char *str, size_t n); terom@168: terom@168: /** terom@168: * Assert that the given \a str is NULL. terom@168: */ terom@194: #define assert_strnull(str) _ASSERT_FUNC_CALL(_assert_strnull, str) terom@194: void _assert_strnull (_ASSERT_FUNC_ARGS, const char *str); terom@168: terom@168: /** terom@168: * Assert that the given error code is SUCCESS. terom@168: */ terom@194: #define assert_success(err) _ASSERT_FUNC_CALL(_assert_success, err) terom@194: void _assert_success (_ASSERT_FUNC_ARGS, err_t err); terom@168: terom@168: /** terom@194: * Assert that the given actual error code \a err matches the expected error code \a should_be. terom@168: */ terom@194: #define assert_err(is, should_be) _ASSERT_FUNC_CALL(_assert_err, is, should_be) terom@194: void _assert_err (_ASSERT_FUNC_ARGS, err_t is, err_t should_be); terom@168: terom@168: /** terom@168: * Assert that the given actual error \a is matches the expected error \a should_be terom@168: */ terom@194: #define assert_error(is, should_be) _ASSERT_FUNC_CALL(_assert_error, is, should_be) terom@194: void _assert_error (_ASSERT_FUNC_ARGS, error_t *is, error_t *should_be); terom@168: terom@168: #endif