mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-24 18:10:06 +01:00
test: add litest string comparison macros
Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1059>
This commit is contained in:
parent
9a5f888795
commit
0bc2bf60d2
3 changed files with 86 additions and 0 deletions
|
|
@ -420,6 +420,38 @@ START_TEST(litest_double_ge_fails)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(litest_string_eq_ne)
|
||||
{
|
||||
litest_assert_str_eq("foo", "foo");
|
||||
litest_assert_str_ne("foo", "bar");
|
||||
litest_assert_str_ne("foo", "foobar");
|
||||
litest_assert_str_ne("foobar", "foo");
|
||||
|
||||
const char *a1 = "a";
|
||||
const char *a2 = "a";
|
||||
const char *b = "b";
|
||||
|
||||
litest_assert_str_eq(NULL, NULL);
|
||||
litest_assert_str_eq(a1, a2);
|
||||
litest_assert_str_ne(a1, b);
|
||||
litest_assert_str_ne(a2, b);
|
||||
litest_assert_str_ne(a2, b);
|
||||
litest_assert_str_ne(b, NULL);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(litest_string_eq_fails)
|
||||
{
|
||||
litest_assert_str_eq("foo", "bar");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(litest_string_ne_fails)
|
||||
{
|
||||
litest_assert_str_ne("foo", "foo");
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(zalloc_overflow)
|
||||
{
|
||||
zalloc((size_t)-1);
|
||||
|
|
@ -514,6 +546,12 @@ litest_assert_macros_suite(void)
|
|||
tcase_add_test_raise_signal(tc, litest_double_ge_fails, SIGABRT);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("string comparison ");
|
||||
tcase_add_test(tc, litest_string_eq_ne);
|
||||
tcase_add_test_raise_signal(tc, litest_string_eq_fails, SIGABRT);
|
||||
tcase_add_test_raise_signal(tc, litest_string_ne_fails, SIGABRT);
|
||||
suite_add_tcase(s, tc);
|
||||
|
||||
tc = tcase_create("zalloc ");
|
||||
tcase_add_test(tc, zalloc_max_size);
|
||||
tcase_add_test_raise_signal(tc, zalloc_overflow, SIGABRT);
|
||||
|
|
|
|||
|
|
@ -258,6 +258,23 @@ litest_fail_comparison_ptr(const char *file,
|
|||
abort();
|
||||
}
|
||||
|
||||
__attribute__((noreturn))
|
||||
void
|
||||
litest_fail_comparison_str(const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *comparison,
|
||||
const char *operator,
|
||||
const char *astr,
|
||||
const char *bstr)
|
||||
{
|
||||
litest_log("FAILED COMPARISON: %s %s %s\n", astr, operator, bstr);
|
||||
litest_log("Resolved to: %s %s %s\n", astr, operator, bstr);
|
||||
litest_log("in %s() (%s:%d)\n", func, file, line);
|
||||
litest_backtrace();
|
||||
abort();
|
||||
}
|
||||
|
||||
struct test {
|
||||
struct list node;
|
||||
char *name;
|
||||
|
|
|
|||
|
|
@ -131,6 +131,15 @@ litest_fail_comparison_ptr(const char *file,
|
|||
const char *func,
|
||||
const char *comparison);
|
||||
|
||||
void
|
||||
litest_fail_comparison_str(const char *file,
|
||||
int line,
|
||||
const char *func,
|
||||
const char *comparison,
|
||||
const char *operator,
|
||||
const char *astr,
|
||||
const char *bstr);
|
||||
|
||||
#define litest_assert(cond) \
|
||||
do { \
|
||||
if (!(cond)) \
|
||||
|
|
@ -222,6 +231,28 @@ litest_fail_comparison_ptr(const char *file,
|
|||
#define litest_assert_ptr_notnull(a_) \
|
||||
litest_assert_comparison_ptr_(a_, !=, NULL)
|
||||
|
||||
#define litest_assert_str_eq(a_, b_) \
|
||||
do { \
|
||||
const char *_a = a_; \
|
||||
const char *_b = b_; \
|
||||
if (!streq(_a, _b)) \
|
||||
litest_fail_comparison_str(__FILE__, __LINE__, __func__,\
|
||||
#a_ " == " #b_, \
|
||||
"==", \
|
||||
_a, _b); \
|
||||
} while(0)
|
||||
|
||||
#define litest_assert_str_ne(a_, b_) \
|
||||
do { \
|
||||
const char *_a = a_; \
|
||||
const char *_b = b_; \
|
||||
if (streq(_a, _b)) \
|
||||
litest_fail_comparison_str(__FILE__, __LINE__, __func__,\
|
||||
#a_ " != " #b_, \
|
||||
"!=", \
|
||||
_a, _b); \
|
||||
} while(0)
|
||||
|
||||
#define LITEST_DEFAULT_EPSILON 0.001
|
||||
|
||||
#define litest_assert_double_eq_epsilon(a_, b_, epsilon_)\
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue