diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 4b2554991..6065c15d1 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -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 diff --git a/glib/gtestutils.c b/glib/gtestutils.c index 7da2fc061..0a9ba0a26 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -391,6 +391,21 @@ * Since: 2.38 */ +/** + * 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) diff --git a/glib/gtestutils.h b/glib/gtestutils.h index 9700f38fc..0118c5086 100644 --- a/glib/gtestutils.h +++ b/glib/gtestutils.h @@ -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)