test: add macros to compare enum values
authorPeter Hutterer <peter.hutterer@who-t.net>
Mon, 16 Sep 2024 06:30:40 +0000 (16:30 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 15 Oct 2024 02:44:27 +0000 (12:44 +1000)
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>

test/litest.h

index 0f192c9d0c093c7571ca5c701a27e8bc3f92ffa0..448faf47e1451f009e23aed33b12c542e3c0cbbb 100644 (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_)