]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
unit-tests: Add a ck_assert_chunk_eq() convenience macro
authorMartin Willi <martin@revosec.ch>
Tue, 11 Feb 2014 12:55:56 +0000 (13:55 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 30 Apr 2014 15:22:48 +0000 (17:22 +0200)
src/libstrongswan/tests/test_suite.h

index c44f149f558932fa4ba8fb2f11ce52b53c846d64..2b1a64c2df86a5c0f39496e4e1f4da88c6b84718 100644 (file)
@@ -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, ...) \
 ({ \