tests: check for no pending expected_messages on exit of tests

On the end of the test there should be no unchecked expected
messages. Register a destructor function in nmtst to assert
against that.

Also call nmtst_free() in the destructor. That way, we always release
the allocated data without requiring the test to do it explicitly.

(cherry picked from commit bb90127c2a)
This commit is contained in:
Thomas Haller 2015-01-07 20:32:11 +01:00
parent 0074bf032b
commit fec4e68f4d

View file

@ -130,7 +130,14 @@ struct __nmtst_internal
extern struct __nmtst_internal __nmtst_internal;
#define NMTST_DEFINE() \
struct __nmtst_internal __nmtst_internal = { 0 };
struct __nmtst_internal __nmtst_internal = { 0 }; \
\
__attribute__ ((destructor)) static void \
_nmtst_exit (void) \
{ \
nmtst_free (); \
g_test_assert_expected_messages (); \
}
inline static gboolean
@ -218,7 +225,6 @@ nmtst_free (void)
inline static void
__nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_level, const char *log_domains, gboolean *out_set_logging)
{
static gsize atexit_registered = 0;
const char *nmtst_debug;
gboolean is_debug = FALSE;
char *c_log_level = NULL, *c_log_domains = NULL;
@ -381,11 +387,6 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_
g_free (c_log_level);
g_free (c_log_domains);
if (g_once_init_enter (&atexit_registered)) {
atexit (nmtst_free);
g_once_init_leave (&atexit_registered, 1);
}
#ifdef __NETWORKMANAGER_UTILS_H__
/* ensure that monotonic timestamp is called (because it initially logs a line) */
nm_utils_get_monotonic_timestamp_s ();