]> granicus.if.org Git - check/commitdiff
Add ck_assert_pstr_* macros with ability to compare undefined (NULL) strings
authorDotsenko Andrey <cnconlinux@gmail.com>
Sat, 10 Dec 2016 19:11:14 +0000 (22:11 +0300)
committerDotsenko Andrey <cnconlinux@gmail.com>
Mon, 12 Dec 2016 04:48:55 +0000 (07:48 +0300)
src/check.h.in

index 3b85facf8eb5ce0bddec821ac8975e1b09ca7012..e78d6907e75e3d46be07445e4a81aa72acbe7d78 100644 (file)
@@ -1487,6 +1487,46 @@ do { \
  */
 #define ck_assert_str_ge(X, Y) _ck_assert_str(X, >=, Y, 0, 0)
 
+/**
+ * Check two strings to determine if 0==strcmp(X,Y) or if both are undefined 
+ *
+ * If both X and Y are NULL the test passes. However, if only one is NULL
+ * the test fails.
+ * If not ((X==NULL)&&(Y==NULL)) || (0==strcmp(X,Y)), the test fails.
+ *
+ * @param X string
+ * @param Y string to compare against X
+ *
+ * @note If the check fails, the remaining of the test is aborted
+ *
+ * @since 0.11.0
+ */
+#define ck_assert_pstr_eq(X, Y) _ck_assert_str(X, ==, Y, 1, 0)
+
+/**
+ * Check two strings to determine if 0!=strcmp(X,Y) or one of them is undefined
+ *
+ * If either X or Y is NULL the test passes, however if both are NULL
+ * the test fails.
+ * If not (X!=NULL)&&(Y!=NULL)&&(0!=strcmp(X,Y)), the test fails.
+ *
+ * @param X string
+ * @param Y string to compare against X
+ *
+ * @note If the check fails, the remaining of the test is aborted
+ *
+ * @since 0.11.0
+ */
+#define ck_assert_pstr_ne(X, Y) _ck_assert_str(X, !=, Y, 0, 1)
+
+/* Memory location comparison macros with improved output compared to ck_assert() */
+/* OP might be any operator that can be used in '0 OP memcmp(X,Y,L)' comparison */
+/* The x and y parameter swap in memcmp() is needed to handle >, >=, <, <= operators */
+/* Output is limited to CK_MAX_ASSERT_MEM_PRINT_SIZE bytes */
+#ifndef CK_MAX_ASSERT_MEM_PRINT_SIZE
+#define CK_MAX_ASSERT_MEM_PRINT_SIZE 64
+#endif
+
 /* Memory location comparison macros with improved output compared to ck_assert() */
 /* OP might be any operator that can be used in '0 OP memcmp(X,Y,L)' comparison */
 /* The x and y parameter swap in memcmp() is needed to handle >, >=, <, <= operators */