gtestutils: add g_assert_nonnull() to go with g_assert_null()

https://bugzilla.gnome.org/show_bug.cgi?id=711800
This commit is contained in:
Dan Winship 2013-11-10 15:27:26 -05:00
parent f4c30feb95
commit 97fac93670
3 changed files with 21 additions and 1 deletions

View 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

View File

@ -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)

View 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)