From 151c2feae683c9c208216b43089de7d35dd90ffa Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 16 Sep 2024 16:30:40 +1000 Subject: [PATCH] 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: --- test/litest.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/litest.h b/test/litest.h index 0f192c9d..448faf47 100644 --- a/test/litest.h +++ b/test/litest.h @@ -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_) -- 2.34.1