]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: introduce ASSERT_PTR_EQ()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 6 Mar 2025 03:11:43 +0000 (12:11 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 12 Mar 2025 16:48:50 +0000 (01:48 +0900)
src/shared/tests.h

index 8d0e6a4bcf3e8ad30265628a1a729cb3eaec3b63..07c4eeefbdddf55f6bd12aafee5f7ffdd1a68ac3 100644 (file)
@@ -418,6 +418,16 @@ static inline int run_test_table(void) {
                 }                                                                                               \
         })
 
+#define ASSERT_PTR_EQ(expr1, expr2)                                                                             \
+        ({                                                                                                      \
+                const void *_expr1 = (expr1), *_expr2 = (expr2);                                                \
+                if (_expr1 != _expr2) {                                                                         \
+                        log_error("%s:%i: Assertion failed: expected \"%s == %s\", got \"0x%p != 0x%p\"",       \
+                                  PROJECT_FILE, __LINE__, #expr1, #expr2, _expr1, _expr2);                      \
+                        abort();                                                                                \
+                }                                                                                               \
+        })
+
 /* DECIMAL_STR_FMT() uses _Generic which cannot be used in string concatenation so we have to format the
  * input into strings first and then format those into the final assertion message. */