gtestutils: add g_assert_nonnull() to go with g_assert_null()
authorDan Winship <danw@gnome.org>
Sun, 10 Nov 2013 20:27:26 +0000 (15:27 -0500)
committerDan Winship <danw@gnome.org>
Sun, 24 Nov 2013 19:59:51 +0000 (14:59 -0500)
https://bugzilla.gnome.org/show_bug.cgi?id=711800

docs/reference/glib/glib-sections.txt
glib/gtestutils.c
glib/gtestutils.h

index 4b25549..6065c15 100644 (file)
@@ -2977,6 +2977,7 @@ g_assert_error
 g_assert_true
 g_assert_false
 g_assert_null
+g_assert_nonnull
 g_test_set_nonfatal_assertions
 
 GTestCase
index 7da2fc0..0a9ba0a 100644 (file)
  */
 
 /**
+ * g_assert_nonnull:
+ * @expr: the expression to check
+ *
+ * Debugging macro to check an expression is not %NULL.
+ *
+ * If the assertion fails (i.e. the expression is %NULL),
+ * an error message is logged and the application is either
+ * terminated or the testcase marked as failed.
+ *
+ * See g_test_set_nonfatal_assertions().
+ *
+ * Since: 2.40
+ */
+
+/**
  * g_assert_cmpstr:
  * @s1: a string (may be %NULL)
  * @cmp: The comparison operator to use.
index 9700f38..0118c50 100644 (file)
@@ -74,7 +74,11 @@ typedef void (*GTestFixtureFunc) (gpointer      fixture,
                                                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 \
+#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)
+#define g_assert_nonnull(expr)          do { if G_LIKELY ((expr) != NULL) ; else \
                                                g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
                                                                     #expr); \
                                            } while (0)