summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-10-06 12:00:47 +0200
committerThomas Haller <thaller@redhat.com>2022-10-14 17:37:02 +0200
commit67ee0363899b3c926118a53515b1a633377f1d82 (patch)
tree392caef18d3c60d41015f7bdeadacf252900beb1
parente03b8fa44743d0ce91a849ea6f64cd99a0476e19 (diff)
downloadNetworkManager-67ee0363899b3c926118a53515b1a633377f1d82.tar.gz
glib-aux/tests: add nmtst_true_once() helper
-rw-r--r--src/libnm-glib-aux/nm-test-utils.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h
index 144b3a85b7..f3e558dfe0 100644
--- a/src/libnm-glib-aux/nm-test-utils.h
+++ b/src/libnm-glib-aux/nm-test-utils.h
@@ -1192,6 +1192,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)
{
g_assert_not_reached();