[glib] Add g_assert_true, g_assert_false and g_assert_null
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add g_assert_true, g_assert_false and g_assert_null
- Date: Sat, 17 Aug 2013 21:28:33 +0000 (UTC)
commit b63739e60ea03364a7a06e0c697b5c6c4690d0b6
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 2 12:53:05 2013 -0500
Add g_assert_true, g_assert_false and g_assert_null
These are just like g_assert(), but using a different entry
point for the message, so we can repurpose them together
with the other assertion macros.
https://bugzilla.gnome.org/show_bug.cgi?id=692125
glib/gtestutils.c | 27 +++++++++++++++++++++++++++
glib/gtestutils.h | 15 ++++++++++++++-
2 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/glib/gtestutils.c b/glib/gtestutils.c
index f1116a5..948f57c 100644
--- a/glib/gtestutils.c
+++ b/glib/gtestutils.c
@@ -349,6 +349,33 @@
*/
/**
+ * g_assert_true:
+ * @expr: the expression to check
+ *
+ * Debugging macro to check that an expression is true.
+ *
+ * Since: 2.38
+ */
+
+/**
+ * g_assert_false:
+ * @expr: the expression to check
+ *
+ * Debugging macro to check an expression is false.
+ *
+ * Since: 2.38
+ */
+
+/**
+ * g_assert_null:
+ * @expr: the expression to check
+ *
+ * Debugging macro to check an expression is %NULL.
+ *
+ * Since: 2.38
+ */
+
+/**
* g_assert_cmpstr:
* @s1: a string (may be %NULL)
* @cmp: The comparison operator to use.
diff --git a/glib/gtestutils.h b/glib/gtestutils.h
index ba8aa4b..65a8c09 100644
--- a/glib/gtestutils.h
+++ b/glib/gtestutils.h
@@ -66,6 +66,18 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
#define g_assert_error(err, dom, c) do { if (!err || (err)->domain != dom || (err)->code != c) \
g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
#err, err, dom, c); } while (0)
+#define g_assert_true(expr) do { if G_LIKELY (expr) ; else \
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
+ #expr); \
+ } while (0)
+#define g_assert_false(expr) do { if G_LIKELY (!(expr)) ; else \
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
+ #expr); \
+ } while (0)
+#define g_assert_null(expr) do { if G_LIKELY ((expr) == NULL) ; else \
+ g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
+ #expr); \
+ } while (0)
#ifdef G_DISABLE_ASSERT
#define g_assert_not_reached() do { (void) 0; } while (0)
#define g_assert(expr) do { (void) 0; } while (0)
@@ -73,7 +85,8 @@ typedef void (*GTestFixtureFunc) (gpointer fixture,
#define g_assert_not_reached() do { g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, NULL); } while (0)
#define g_assert(expr) do { if G_LIKELY (expr) ; else \
g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__,
G_STRFUNC, \
- #expr); } while (0)
+ #expr); \
+ } while (0)
#endif /* !G_DISABLE_ASSERT */
GLIB_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]