From: Dan Winship Date: Sun, 10 Nov 2013 20:27:26 +0000 (-0500) Subject: gtestutils: add g_assert_nonnull() to go with g_assert_null() X-Git-Tag: 2.39.2~102 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97fac936708863a52d46cfb0ec3259e1b2c03d29;p=platform%2Fupstream%2Fglib.git gtestutils: add g_assert_nonnull() to go with g_assert_null() https://bugzilla.gnome.org/show_bug.cgi?id=711800 --- diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 4b25549..6065c15 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 7da2fc0..0a9ba0a 100644 --- a/glib/gtestutils.c +++ b/glib/gtestutils.c @@ -392,6 +392,21 @@ */ /** + * 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. diff --git a/glib/gtestutils.h b/glib/gtestutils.h index 9700f38..0118c50 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)