glib-aux/tests: add nmtst_true_once() helper

This commit is contained in:
Thomas Haller 2022-10-06 12:00:47 +02:00
parent e03b8fa447
commit 67ee036389
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -1191,6 +1191,28 @@ nmtst_get_rand_word_length(GRand *rand)
/*****************************************************************************/
static inline gboolean
nmtst_true_once(gboolean *state, gboolean new_val)
{
/* Returns only once a TRUE flag. When returning TRUE,
* it will be remembered in "state" and future invocations
* return FALSE.
*
* Also, if "new_val" is FALSE, it won't return TRUE.
*
* The point is to do an action once (depending on "new_val"),
* and remember it in "state".
*/
if (!new_val)
return FALSE;
if (*state)
return FALSE;
*state = TRUE;
return TRUE;
}
/*****************************************************************************/
static inline gboolean
nmtst_g_source_assert_not_called(gpointer user_data)
{