utest_assert.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-19 MurphyZhao the first version
  9. */
  10. #ifndef __UTEST_ASSERT_H__
  11. #define __UTEST_ASSERT_H__
  12. #include "utest.h"
  13. #include <rtthread.h>
  14. void utest_assert(int value, const char *file, int line, const char *func, const char *msg);
  15. void utest_assert_string(const char *a, const char *b, rt_bool_t equal, const char *file, int line, const char *func, const char *msg);
  16. #define __utest_assert(value, msg) utest_assert(value, __FILE__, __LINE__, __func__, msg)
  17. #define uassert_true(value) __utest_assert(value, "(" #value ") is false")
  18. #define uassert_false(value) __utest_assert(!(value), "(" #value ") is true")
  19. #define uassert_null(value) __utest_assert((value) == NULL, "(" #value ") is not null")
  20. #define uassert_not_null(value) __utest_assert((value) != NULL, "(" #value ") is null")
  21. #define uassert_int_equal(a, b) __utest_assert((a) == (b), "(" #a ") not equal to (" #b ")")
  22. #define uassert_int_not_equal(a, b) __utest_assert((a) != (b), "(" #a ") equal to (" #b ")")
  23. #define uassert_str_equal(a, b) utest_assert_string((const char*)(a), (const char*)(b), RT_TRUE, __FILE__, __LINE__, __func__, "string not equal")
  24. #define uassert_str_not_equal(a, b) utest_assert_string((const char*)(a), (const char*)(b), RT_FALSE, __FILE__, __LINE__, __func__, "string equal")
  25. #define uassert_in_range(value, min, max) __utest_assert(((value >= min) && (value <= max)), "(" #value ") not in range("#min","#max")")
  26. #define uassert_not_in_range(value, min, max) __utest_assert(!((value >= min) && (value <= max)), "(" #value ") in range("#min","#max")")
  27. #endif /* __UTEST_ASSERT_H__ */