From: Martin Willi Date: Tue, 11 Feb 2014 12:55:56 +0000 (+0100) Subject: unit-tests: Add a ck_assert_chunk_eq() convenience macro X-Git-Tag: 5.2.0dr2~13^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=20924ae28f0b3de406507e784cd9ac5bf9fd87f3;p=thirdparty%2Fstrongswan.git unit-tests: Add a ck_assert_chunk_eq() convenience macro --- diff --git a/src/libstrongswan/tests/test_suite.h b/src/libstrongswan/tests/test_suite.h index c44f149f55..2b1a64c2df 100644 --- a/src/libstrongswan/tests/test_suite.h +++ b/src/libstrongswan/tests/test_suite.h @@ -269,6 +269,23 @@ void test_fail_msg(const char *file, int line, char *fmt, ...); } \ }) +/** + * Check if two chunks are equal, fail test if not + * + * @param a first chunk + * @param b second chunk + */ +#define test_chunk_eq(a, b) \ +({ \ + chunk_t _a = (chunk_t)a; \ + chunk_t _b = (chunk_t)b; \ + if (_a.len != _b.len || !memeq(a.ptr, b.ptr, a.len)) \ + { \ + test_fail_msg(__FILE__, __LINE__, \ + #a " != " #b " (\"%#B\" != \"%#B\")", &_a, &_b); \ + } \ +}) + /** * Check if a statement evaluates to TRUE, fail test if not * @@ -306,6 +323,7 @@ void test_fail_msg(const char *file, int line, char *fmt, ...); #define ck_assert test_assert #define ck_assert_msg test_assert_msg #define ck_assert_str_eq test_str_eq +#define ck_assert_chunk_eq test_chunk_eq #define fail(fmt, ...) test_fail_msg(__FILE__, __LINE__, fmt, ##__VA_ARGS__) #define fail_if(x, fmt, ...) \ ({ \