Blame SOURCES/0233-testsuite-assert-for-common-function-results.patch

4b6aa8
From 6e854f3c2c159ccb25f76bed3dbcecafbee8fb34 Mon Sep 17 00:00:00 2001
4b6aa8
From: Jakub Filak <jfilak@redhat.com>
4b6aa8
Date: Fri, 8 Apr 2016 08:47:05 +0200
4b6aa8
Subject: [PATCH] testsuite: assert for common function results
4b6aa8
4b6aa8
Signed-off-by: Jakub Filak <jfilak@redhat.com>
4b6aa8
---
4b6aa8
 tests/helpers/testsuite.h | 22 +++++++++++++++++++++-
4b6aa8
 1 file changed, 21 insertions(+), 1 deletion(-)
4b6aa8
4b6aa8
diff --git a/tests/helpers/testsuite.h b/tests/helpers/testsuite.h
4b6aa8
index bc7abf1d..809edbc6 100644
4b6aa8
--- a/tests/helpers/testsuite.h
4b6aa8
+++ b/tests/helpers/testsuite.h
4b6aa8
@@ -217,7 +217,7 @@ FILE *g_testsuite_output_stream = 0;
4b6aa8
         const char *l_ts_lhs = (actual); \
4b6aa8
         const char *l_ts_rhs = (expected); \
4b6aa8
         if (l_ts_lhs == NULL && l_ts_rhs != NULL) { \
4b6aa8
-            TS_FAILURE("%s ("#actual" == "#expected")\n\tActual  : NULL\n\tExpected: %p\n", message ? message : "Assert", l_ts_rhs); \
4b6aa8
+            TS_FAILURE("%s ("#actual" == "#expected")\n\tActual  : NULL\n\tExpected: %s\n", message ? message : "Assert", l_ts_rhs); \
4b6aa8
         } \
4b6aa8
         else if (l_ts_lhs != NULL && l_ts_rhs == NULL) { \
4b6aa8
             TS_FAILURE("%s ("#actual" == "#expected")\n\tActual  : %s\n\tExpected: NULL\n", message ? message : "Assert", l_ts_lhs); \
4b6aa8
@@ -307,4 +307,24 @@ FILE *g_testsuite_output_stream = 0;
4b6aa8
     TS_ASSERT_PTR_OP_MESSAGE(actual, ==, expected, NULL);
4b6aa8
 
4b6aa8
 
4b6aa8
+
4b6aa8
+/*
4b6aa8
+ * Standard functions returning non-0 on errors
4b6aa8
+ */
4b6aa8
+
4b6aa8
+#define TS_ASSERT_FUNCTION_MESSAGE(call, message) \
4b6aa8
+    do { \
4b6aa8
+        const int l_ts_lhs = call; \
4b6aa8
+        if (l_ts_lhs == 0) { \
4b6aa8
+            TS_SUCCESS("%s ('"#call"')\n", message ? message : "Function SUCCEEDED"); \
4b6aa8
+        } \
4b6aa8
+        else { \
4b6aa8
+            TS_FAILURE("%s ('"#call"')\n\tCode  : %d\n", message ? message : "Function FAILED", l_ts_lhs); \
4b6aa8
+        } \
4b6aa8
+    } while(0)
4b6aa8
+
4b6aa8
+
4b6aa8
+#define TS_ASSERT_FUNCTION(call) \
4b6aa8
+    TS_ASSERT_FUNCTION_MESSAGE(call, NULL)
4b6aa8
+
4b6aa8
 #endif/*LIBREPORT_TESTSUITE_H*/
4b6aa8
-- 
4b6aa8
2.17.2
4b6aa8