test: add macros to compare enum values

This requires switching a lot of int_eq/int_ne over to enum_eq/enum_ne
because the compiler doesn't infer the right type from a harcoded enum
value - it just defaults to int.

Part-of: <https://gitlab.freedesktop.org/libinput/libinput/-/merge_requests/1059>
This commit is contained in:
Peter Hutterer 2024-09-16 16:30:40 +10:00
parent 5f4f72dca4
commit 151c2feae6

View file

@ -192,6 +192,22 @@ litest_fail_comparison_str(const char *file,
litest_abort_msg("Unexpected errno: %d (%s)", _e, strerror(_e)); \
} while(0);
#define litest_assert_comparison_enum_(a_, op_, b_) \
do { \
__typeof__(a_) _a = a_; \
__typeof__(a_) _b = b_; \
if (!((_a) op_ (_b))) \
litest_fail_comparison_int(__FILE__, __LINE__, __func__,\
#op_, (int)_a, (int)_b, \
#a_, #b_); \
} while(0)
#define litest_assert_enum_eq(a_, b_) \
litest_assert_comparison_enum_(a_, ==, b_)
#define litest_assert_enum_ne(a_, b_) \
litest_assert_comparison_enum_(a_, !=, b_)
#define litest_assert_int_eq(a_, b_) \
litest_assert_comparison_int_(a_, ==, b_)