[tepl] testsuite: tepl-test-utils: wait signal functions
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] testsuite: tepl-test-utils: wait signal functions
- Date: Fri, 22 May 2020 12:51:13 +0000 (UTC)
commit 566ea5d91f780a7be889959ef9cc8c9e40b681c9
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri May 22 14:44:17 2020 +0200
testsuite: tepl-test-utils: wait signal functions
testsuite/tepl-test-utils.c | 48 +++++++++++++++++++++++++++++++++
testsuite/tepl-test-utils.h | 8 ++++++
testsuite/test-file.c | 66 +++++++--------------------------------------
3 files changed, 65 insertions(+), 57 deletions(-)
---
diff --git a/testsuite/tepl-test-utils.c b/testsuite/tepl-test-utils.c
index dc5c1e0..e574d49 100644
--- a/testsuite/tepl-test-utils.c
+++ b/testsuite/tepl-test-utils.c
@@ -3,6 +3,7 @@
*/
#include "tepl-test-utils.h"
+#include <gtk/gtk.h>
/* Common utility functions for the unit tests. */
@@ -23,3 +24,50 @@ _tepl_test_utils_set_file_content (GFile *file,
&error);
g_assert_no_error (error);
}
+
+struct _TeplWaitSignalData
+{
+ guint signal_received : 1;
+ guint nested_main_loop : 1;
+};
+
+static void
+wait_signal_cb (TeplWaitSignalData *data)
+{
+ data->signal_received = TRUE;
+
+ if (data->nested_main_loop)
+ {
+ gtk_main_quit ();
+ }
+}
+
+TeplWaitSignalData *
+_tepl_test_utils_wait_signal_setup (GObject *object,
+ const gchar *detailed_signal_name)
+{
+ TeplWaitSignalData *data;
+
+ data = g_new0 (TeplWaitSignalData, 1);
+ data->signal_received = FALSE;
+ data->nested_main_loop = FALSE;
+
+ g_signal_connect_swapped (object,
+ detailed_signal_name,
+ G_CALLBACK (wait_signal_cb),
+ data);
+
+ return data;
+}
+
+void
+_tepl_test_utils_wait_signal (TeplWaitSignalData *data)
+{
+ if (!data->signal_received)
+ {
+ data->nested_main_loop = TRUE;
+ gtk_main ();
+ }
+
+ g_free (data);
+}
diff --git a/testsuite/tepl-test-utils.h b/testsuite/tepl-test-utils.h
index 188d5fa..cfa1a2e 100644
--- a/testsuite/tepl-test-utils.h
+++ b/testsuite/tepl-test-utils.h
@@ -9,9 +9,17 @@
G_BEGIN_DECLS
+typedef struct _TeplWaitSignalData TeplWaitSignalData;
+
void _tepl_test_utils_set_file_content (GFile *file,
const gchar *content);
+TeplWaitSignalData *
+ _tepl_test_utils_wait_signal_setup (GObject *object,
+ const gchar *detailed_signal_name);
+
+void _tepl_test_utils_wait_signal (TeplWaitSignalData *data);
+
G_END_DECLS
#endif /* TEPL_TEST_UTILS_H */
diff --git a/testsuite/test-file.c b/testsuite/test-file.c
index f47be4f..f288abe 100644
--- a/testsuite/test-file.c
+++ b/testsuite/test-file.c
@@ -7,54 +7,6 @@
#include <glib/gi18n-lib.h>
#include "tepl-test-utils.h"
-typedef struct _WaitSignalData WaitSignalData;
-struct _WaitSignalData
-{
- guint signal_received : 1;
- guint nested_main_loop : 1;
-};
-
-static void
-wait_signal_cb (WaitSignalData *data)
-{
- data->signal_received = TRUE;
-
- if (data->nested_main_loop)
- {
- gtk_main_quit ();
- }
-}
-
-static WaitSignalData *
-wait_signal_setup (GObject *object,
- const gchar *detailed_signal_name)
-{
- WaitSignalData *data;
-
- data = g_new0 (WaitSignalData, 1);
- data->signal_received = FALSE;
- data->nested_main_loop = FALSE;
-
- g_signal_connect_swapped (object,
- detailed_signal_name,
- G_CALLBACK (wait_signal_cb),
- data);
-
- return data;
-}
-
-static void
-wait_signal (WaitSignalData *data)
-{
- if (!data->signal_received)
- {
- data->nested_main_loop = TRUE;
- gtk_main ();
- }
-
- g_free (data);
-}
-
static void
check_short_name (TeplFile *file,
const gchar *expected_short_name)
@@ -123,7 +75,7 @@ test_short_name (void)
{
TeplFile *file;
GFile *location;
- WaitSignalData *data;
+ TeplWaitSignalData *data;
GError *error = NULL;
location = g_file_new_build_filename (g_get_tmp_dir (), "tepl-test-file", NULL);
@@ -137,9 +89,9 @@ test_short_name (void)
g_assert_no_error (error);
file = tepl_file_new ();
- data = wait_signal_setup (G_OBJECT (file), "notify::short-name");
+ data = _tepl_test_utils_wait_signal_setup (G_OBJECT (file), "notify::short-name");
tepl_file_set_location (file, location);
- wait_signal (data);
+ _tepl_test_utils_wait_signal (data);
check_short_name (file, "tepl-test-file");
g_object_unref (file);
@@ -147,9 +99,9 @@ test_short_name (void)
_tepl_test_utils_set_file_content (location, "file content");
file = tepl_file_new ();
- data = wait_signal_setup (G_OBJECT (file), "notify::short-name");
+ data = _tepl_test_utils_wait_signal_setup (G_OBJECT (file), "notify::short-name");
tepl_file_set_location (file, location);
- wait_signal (data);
+ _tepl_test_utils_wait_signal (data);
check_short_name (file, "tepl-test-file");
g_object_unref (file);
g_object_unref (location);
@@ -157,9 +109,9 @@ test_short_name (void)
/* Test the special case for a remote location that has no parent GFile. */
location = g_file_new_for_uri ("https://swilmet.be";);
file = tepl_file_new ();
- data = wait_signal_setup (G_OBJECT (file), "notify::short-name");
+ data = _tepl_test_utils_wait_signal_setup (G_OBJECT (file), "notify::short-name");
tepl_file_set_location (file, location);
- wait_signal (data);
+ _tepl_test_utils_wait_signal (data);
check_short_name (file, "https://swilmet.be";);
g_object_unref (file);
g_object_unref (location);
@@ -169,9 +121,9 @@ test_short_name (void)
// have the https://swilmet.be prefix, with an optional trailing slash.
location = g_file_new_for_uri ("https://swilmet.be/";);
file = tepl_file_new ();
- data = wait_signal_setup (G_OBJECT (file), "notify::short-name");
+ data = _tepl_test_utils_wait_signal_setup (G_OBJECT (file), "notify::short-name");
tepl_file_set_location (file, location);
- wait_signal (data);
+ _tepl_test_utils_wait_signal (data);
check_short_name (file, "https://swilmet.be/";);
g_object_unref (file);
g_object_unref (location);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]