summaryrefslogtreecommitdiff
path: root/include/asterisk/test.h
diff options
context:
space:
mode:
authorGeorge Joseph <george.joseph@fairview5.com>2015-05-05 19:22:13 -0600
committerGeorge Joseph <george.joseph@fairview5.com>2015-05-06 22:37:16 -0500
commitc886be5df271a01497189d3b4ddd52b29c3bca01 (patch)
tree5321db07573baef883a716af0470abf8de88ddad /include/asterisk/test.h
parenta4d16c182221b1796485a45b523275601aafe5bb (diff)
vector: Additional enhancements and fixes
After using the new vector stuff for real I found... A bug in AST_VECTOR_INSERT_AT that could cause a seg fault. The callbacks needed to be closer to ao2_callback in behavior WRT to CMP_MATCH and CMP_STOP behavior and the ability to return a vector of matched entries. A pre-existing issue with APPEND and REPLACE was also fixed. I also added a new macro to test.h that acts like ast_test_validate but also accepts a return code variable and a cleanup label. As well as printing the error, it sets the rc variable to AST_TEST_FAIL and does a goto to the specified label on error. I had a local version of this in test_vector so I just moved it. ASTERISK-25045 Change-Id: I05e5e47fd02f61964be13b7e8942bab5d61b29cc
Diffstat (limited to 'include/asterisk/test.h')
-rw-r--r--include/asterisk/test.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/asterisk/test.h b/include/asterisk/test.h
index 2ea8332b1..69f88374e 100644
--- a/include/asterisk/test.h
+++ b/include/asterisk/test.h
@@ -389,6 +389,28 @@ int __ast_test_status_update(const char *file, const char *func, int line, struc
} \
} while(0)
+/*!
+ * \brief Check a test condition, report error and goto cleanup label if failed.
+ *
+ * \since 13.4.0
+ *
+ * This macro evaluates \a condition. If the condition evaluates to true (non-zero),
+ * nothing happens. If it evaluates to false (zero), then the failure is printed
+ * using \ref ast_test_status_update, the variable \a rc_variable is set to AST_TEST_FAIL,
+ * and a goto to \a cleanup_label is executed.
+ *
+ * \param test Currently executing test
+ * \param condition Boolean condition to check.
+ * \param rc_variable Variable to receive AST_TEST_FAIL.
+ * \param cleanup_label The label to go to on failure.
+ */
+#define ast_test_validate_cleanup(test, condition, rc_variable, cleanup_label) ({ \
+ if (!(condition)) { \
+ ast_test_status_update((test), "%s: %s\n", "Condition failed", #condition); \
+ rc_variable = AST_TEST_FAIL; \
+ goto cleanup_label; \
+ } \
+})
#endif /* TEST_FRAMEWORK */
#endif /* _AST_TEST_H */