From c4690eeeff8cf1b5c799e8b2272ce8559f207541 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Jan 2020 13:41:14 +0100 Subject: [PATCH] shared/tests: add nmtst_main_context_assert_no_dispatch() helper --- shared/nm-utils/nm-test-utils.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index ef363abaee..6d7084c8d5 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1060,6 +1060,26 @@ _nmtst_main_context_iterate_until_timeout (gpointer user_data) /*****************************************************************************/ +static inline void +nmtst_main_context_assert_no_dispatch (GMainContext *context, + guint timeout_msec) +{ + nm_auto_destroy_and_unref_gsource GSource *source = NULL; + gboolean timeout_hit = FALSE; + + source = g_timeout_source_new (timeout_msec); + g_source_set_callback (source, nmtst_g_source_set_boolean_true, &timeout_hit, NULL); + g_source_attach (source, context); + + while (g_main_context_iteration (context, TRUE)) { + if (timeout_hit) + return; + g_assert_not_reached (); + } +} + +/*****************************************************************************/ + typedef struct { GMainLoop *_main_loop; union {