mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-20 14:19:16 +02:00
tests: Move main loop and test GUID into test functions in gdbus-peer
There’s actually no need for them to be global or reused between unit tests, so move them inside the test functions. This is one step towards eliminating shared state between the unit tests. Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #1912
This commit is contained in:
parent
3f7fa2f955
commit
45d98b8863
@ -1033,6 +1033,9 @@ do_test_peer (void)
|
|||||||
static void
|
static void
|
||||||
test_peer (void)
|
test_peer (void)
|
||||||
{
|
{
|
||||||
|
test_guid = g_dbus_generate_guid ();
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
/* Run this test multiple times using different address formats to ensure
|
/* Run this test multiple times using different address formats to ensure
|
||||||
* they all work.
|
* they all work.
|
||||||
*/
|
*/
|
||||||
@ -1049,6 +1052,9 @@ test_peer (void)
|
|||||||
do_test_peer ();
|
do_test_peer ();
|
||||||
teardown_test_address ();
|
teardown_test_address ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
g_free (test_guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -1064,6 +1070,9 @@ test_peer_signals (void)
|
|||||||
|
|
||||||
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/issues/1620");
|
g_test_bug ("https://gitlab.gnome.org/GNOME/glib/issues/1620");
|
||||||
|
|
||||||
|
test_guid = g_dbus_generate_guid ();
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
setup_test_address ();
|
setup_test_address ();
|
||||||
memset (&data, '\0', sizeof (PeerData));
|
memset (&data, '\0', sizeof (PeerData));
|
||||||
data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
|
data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
|
||||||
@ -1119,6 +1128,9 @@ test_peer_signals (void)
|
|||||||
g_thread_join (service_thread);
|
g_thread_join (service_thread);
|
||||||
|
|
||||||
teardown_test_address ();
|
teardown_test_address ();
|
||||||
|
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
g_free (test_guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -1260,6 +1272,9 @@ delayed_message_processing (void)
|
|||||||
GThread *service_thread;
|
GThread *service_thread;
|
||||||
guint n;
|
guint n;
|
||||||
|
|
||||||
|
test_guid = g_dbus_generate_guid ();
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
setup_test_address ();
|
setup_test_address ();
|
||||||
|
|
||||||
data = g_new0 (DmpData, 1);
|
data = g_new0 (DmpData, 1);
|
||||||
@ -1307,6 +1322,9 @@ delayed_message_processing (void)
|
|||||||
g_thread_join (service_thread);
|
g_thread_join (service_thread);
|
||||||
dmp_data_free (data);
|
dmp_data_free (data);
|
||||||
teardown_test_address ();
|
teardown_test_address ();
|
||||||
|
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
g_free (test_guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -1405,6 +1423,9 @@ test_nonce_tcp (void)
|
|||||||
gboolean res;
|
gboolean res;
|
||||||
const gchar *address;
|
const gchar *address;
|
||||||
|
|
||||||
|
test_guid = g_dbus_generate_guid ();
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
memset (&data, '\0', sizeof (PeerData));
|
memset (&data, '\0', sizeof (PeerData));
|
||||||
data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
|
data.current_connections = g_ptr_array_new_with_free_func (g_object_unref);
|
||||||
|
|
||||||
@ -1512,6 +1533,9 @@ test_nonce_tcp (void)
|
|||||||
g_thread_join (service_thread);
|
g_thread_join (service_thread);
|
||||||
|
|
||||||
g_ptr_array_unref (data.current_connections);
|
g_ptr_array_unref (data.current_connections);
|
||||||
|
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
g_free (test_guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1596,6 +1620,9 @@ test_tcp_anonymous (void)
|
|||||||
GDBusConnection *connection;
|
GDBusConnection *connection;
|
||||||
GError *error;
|
GError *error;
|
||||||
|
|
||||||
|
test_guid = g_dbus_generate_guid ();
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
seen_connection = FALSE;
|
seen_connection = FALSE;
|
||||||
service_thread = g_thread_new ("tcp-anon-service",
|
service_thread = g_thread_new ("tcp-anon-service",
|
||||||
tcp_anonymous_service_thread_func,
|
tcp_anonymous_service_thread_func,
|
||||||
@ -1623,6 +1650,9 @@ test_tcp_anonymous (void)
|
|||||||
server = NULL;
|
server = NULL;
|
||||||
|
|
||||||
g_thread_join (service_thread);
|
g_thread_join (service_thread);
|
||||||
|
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
g_free (test_guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -1767,6 +1797,9 @@ codegen_test_peer (void)
|
|||||||
GVariant *value;
|
GVariant *value;
|
||||||
const gchar *s;
|
const gchar *s;
|
||||||
|
|
||||||
|
test_guid = g_dbus_generate_guid ();
|
||||||
|
loop = g_main_loop_new (NULL, FALSE);
|
||||||
|
|
||||||
setup_test_address ();
|
setup_test_address ();
|
||||||
|
|
||||||
/* bring up a server - we run the server in a different thread to avoid deadlocks */
|
/* bring up a server - we run the server in a different thread to avoid deadlocks */
|
||||||
@ -1874,6 +1907,9 @@ codegen_test_peer (void)
|
|||||||
g_thread_join (service_thread);
|
g_thread_join (service_thread);
|
||||||
|
|
||||||
teardown_test_address ();
|
teardown_test_address ();
|
||||||
|
|
||||||
|
g_main_loop_unref (loop);
|
||||||
|
g_free (test_guid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------------------------------- */
|
||||||
@ -1892,11 +1928,6 @@ main (int argc,
|
|||||||
g_assert (introspection_data != NULL);
|
g_assert (introspection_data != NULL);
|
||||||
test_interface_introspection_data = introspection_data->interfaces[0];
|
test_interface_introspection_data = introspection_data->interfaces[0];
|
||||||
|
|
||||||
test_guid = g_dbus_generate_guid ();
|
|
||||||
|
|
||||||
/* all the tests rely on a shared main loop */
|
|
||||||
loop = g_main_loop_new (NULL, FALSE);
|
|
||||||
|
|
||||||
g_test_add_func ("/gdbus/peer-to-peer", test_peer);
|
g_test_add_func ("/gdbus/peer-to-peer", test_peer);
|
||||||
g_test_add_func ("/gdbus/peer-to-peer/signals", test_peer_signals);
|
g_test_add_func ("/gdbus/peer-to-peer/signals", test_peer_signals);
|
||||||
g_test_add_func ("/gdbus/delayed-message-processing", delayed_message_processing);
|
g_test_add_func ("/gdbus/delayed-message-processing", delayed_message_processing);
|
||||||
@ -1908,8 +1939,6 @@ main (int argc,
|
|||||||
|
|
||||||
ret = g_test_run ();
|
ret = g_test_run ();
|
||||||
|
|
||||||
g_main_loop_unref (loop);
|
|
||||||
g_free (test_guid);
|
|
||||||
g_dbus_node_info_unref (introspection_data);
|
g_dbus_node_info_unref (introspection_data);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user