diff options
Diffstat (limited to 'shared/nm-utils/nm-test-utils.h')
-rw-r--r-- | shared/nm-utils/nm-test-utils.h | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index d0c1937021..25277b2f76 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -999,6 +999,13 @@ nmtst_g_source_set_boolean_true (gpointer user_data) return G_SOURCE_CONTINUE; } +static inline gboolean +nmtst_g_source_nop (gpointer user_data) +{ + g_assert (!user_data); + return G_SOURCE_CONTINUE; +} + /*****************************************************************************/ static inline gboolean @@ -1044,19 +1051,32 @@ _nmtst_main_loop_quit_on_notify (GObject *object, GParamSpec *pspec, gpointer us } #define nmtst_main_loop_quit_on_notify ((GCallback) _nmtst_main_loop_quit_on_notify) -#define nmtst_main_context_iterate_until(context, timeout_msec, condition) \ +#define nmtst_main_context_iterate_until_full(context, timeout_msec, poll_msec, condition) \ ({ \ - nm_auto_destroy_and_unref_gsource GSource *_source = NULL; \ + nm_auto_destroy_and_unref_gsource GSource *_source_timeout = NULL; \ + nm_auto_destroy_and_unref_gsource GSource *_source_poll = NULL; \ GMainContext *_context = (context); \ gboolean _had_timeout = FALSE; \ - typeof(timeout_msec) _timeout_msec0 = (timeout_msec); \ + typeof (timeout_msec) _timeout_msec0 = (timeout_msec); \ + typeof (poll_msec) _poll_msec0 = (poll_msec); \ gint64 _timeout_msec = _timeout_msec0; \ + guint _poll_msec = _poll_msec0; \ \ - g_assert_cmpint(_timeout_msec0, ==, _timeout_msec); \ + g_assert_cmpint (_timeout_msec0, ==, _timeout_msec); \ + g_assert_cmpint (_poll_msec0, ==, _poll_msec); \ \ - _source = g_timeout_source_new (NM_CLAMP (_timeout_msec, 0, (gint64) G_MAXUINT)); \ - g_source_set_callback (_source, nmtst_g_source_set_boolean_true, &_had_timeout, NULL); \ - g_source_attach (_source, _context); \ + _source_timeout = g_timeout_source_new (NM_CLAMP (_timeout_msec, 0, (gint64) G_MAXUINT)); \ + g_source_set_callback (_source_timeout, \ + nmtst_g_source_set_boolean_true, \ + &_had_timeout, \ + NULL); \ + g_source_attach (_source_timeout, _context); \ + \ + if (_poll_msec > 0) { \ + _source_poll = g_timeout_source_new (_poll_msec); \ + g_source_set_callback (_source_poll, nmtst_g_source_nop, NULL, NULL); \ + g_source_attach (_source_poll, _context); \ + } \ \ while (TRUE) { \ if (condition) \ @@ -1069,12 +1089,21 @@ _nmtst_main_loop_quit_on_notify (GObject *object, GParamSpec *pspec, gpointer us !_had_timeout; \ }) -#define nmtst_main_context_iterate_until_assert(context, timeout_msec, condition) \ +#define nmtst_main_context_iterate_until(context, timeout_msec, condition) \ + nmtst_main_context_iterate_until_full ((context), (timeout_msec), 0, condition) + +#define nmtst_main_context_iterate_until_assert_full(context, timeout_msec, poll_msec, condition) \ G_STMT_START { \ - if (!nmtst_main_context_iterate_until (context, timeout_msec, condition)) \ - g_assert (FALSE && #condition); \ + if (!nmtst_main_context_iterate_until_full ((context), \ + (timeout_msec), \ + (poll_msec), \ + condition)) \ + g_assert (FALSE &&#condition); \ } G_STMT_END +#define nmtst_main_context_iterate_until_assert(context, timeout_msec, condition) \ + nmtst_main_context_iterate_until_assert_full ((context), (timeout_msec), 0, condition) + /*****************************************************************************/ static inline const char * |