test: Add ASSERT_EQ_ID128() and ASSERT_NE_ID128()

This commit is contained in:
Daan De Meyer
2024-07-24 18:58:40 +02:00
parent 8eb06fd162
commit 60a4505da4
2 changed files with 37 additions and 0 deletions
+27
View File
@@ -429,3 +429,30 @@ static inline int run_test_table(void) {
abort(); \
} \
})
#define ASSERT_EQ_ID128(expr1, expr2) \
({ \
typeof(expr1) _expr1 = (expr1); \
typeof(expr2) _expr2 = (expr2); \
if (!sd_id128_equal(_expr1, _expr2)) { \
log_error("%s:%i: Assertion failed: \"%s == %s\", but \"%s != %s\"", \
PROJECT_FILE, __LINE__, \
#expr1, #expr2, \
SD_ID128_TO_STRING(_expr1), SD_ID128_TO_STRING(_expr2)); \
abort(); \
} \
})
#define ASSERT_NE_ID128(expr1, expr2) \
({ \
typeof(expr1) _expr1 = (expr1); \
typeof(expr2) _expr2 = (expr2); \
if (sd_id128_equal(_expr1, _expr2)) { \
log_error("%s:%i: Assertion failed: \"%s != %s\", but \"%s == %s\"", \
PROJECT_FILE, __LINE__, \
#expr1, #expr2, \
SD_ID128_TO_STRING(_expr1), SD_ID128_TO_STRING(_expr2)); \
abort(); \
} \
})
+10
View File
@@ -4,6 +4,7 @@
#include <sys/stat.h>
#include "errno-util.h"
#include "id128-util.h"
#include "log.h"
#include "macro.h"
#include "tests.h"
@@ -1186,6 +1187,15 @@ TEST(ASSERT) {
ASSERT_LT(-1, 1);
ASSERT_SIGNAL(ASSERT_LT(0, 0), SIGABRT);
ASSERT_SIGNAL(ASSERT_LT(1, -1), SIGABRT);
ASSERT_EQ_ID128(SD_ID128_NULL, SD_ID128_NULL);
ASSERT_NE_ID128(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8),
SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e));
ASSERT_SIGNAL(
ASSERT_EQ_ID128(SD_ID128_MAKE(51,df,0b,4b,c3,b0,4c,97,80,e2,99,b9,8c,a3,73,b8),
SD_ID128_MAKE(f0,3d,aa,eb,1c,33,4b,43,a7,32,17,29,44,bf,77,2e)),
SIGABRT);
ASSERT_SIGNAL(ASSERT_NE_ID128(SD_ID128_NULL, SD_ID128_NULL), SIGABRT);
}
DEFINE_TEST_MAIN(LOG_INFO);