mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-01 23:13:40 +02:00
tests: Port gdbus-connection to use g_assert_*() rather than g_assert()
g_assert() can be compiled out with G_DISABLE_ASSERT, which renders the test rather useless. Signed-off-by: Philip Withnall <withnall@endlessm.com> Helps: #480
This commit is contained in:
@@ -129,9 +129,9 @@ test_connection_bus_failure (void)
|
||||
*
|
||||
*/
|
||||
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert (error != NULL);
|
||||
g_assert (!g_dbus_error_is_remote_error (error));
|
||||
g_assert (c == NULL);
|
||||
g_assert_nonnull (error);
|
||||
g_assert_false (g_dbus_error_is_remote_error (error));
|
||||
g_assert_null (c);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
@@ -159,8 +159,8 @@ test_connection_life_cycle (void)
|
||||
error = NULL;
|
||||
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (c != NULL);
|
||||
g_assert (!g_dbus_connection_is_closed (c));
|
||||
g_assert_nonnull (c);
|
||||
g_assert_false (g_dbus_connection_is_closed (c));
|
||||
|
||||
/*
|
||||
* Check that singleton handling work
|
||||
@@ -168,8 +168,8 @@ test_connection_life_cycle (void)
|
||||
error = NULL;
|
||||
c2 = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (c2 != NULL);
|
||||
g_assert (c == c2);
|
||||
g_assert_nonnull (c2);
|
||||
g_assert_true (c == c2);
|
||||
g_object_unref (c2);
|
||||
|
||||
/*
|
||||
@@ -177,23 +177,23 @@ test_connection_life_cycle (void)
|
||||
*/
|
||||
c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (c2 != NULL);
|
||||
g_assert (c != c2);
|
||||
g_assert_nonnull (c2);
|
||||
g_assert_true (c != c2);
|
||||
g_object_unref (c2);
|
||||
|
||||
c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (c2 != NULL);
|
||||
g_assert (!g_dbus_connection_is_closed (c2));
|
||||
g_assert_nonnull (c2);
|
||||
g_assert_false (g_dbus_connection_is_closed (c2));
|
||||
ret = g_dbus_connection_close_sync (c2, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret);
|
||||
g_assert_true (ret);
|
||||
_g_assert_signal_received (c2, "closed");
|
||||
g_assert (g_dbus_connection_is_closed (c2));
|
||||
g_assert_true (g_dbus_connection_is_closed (c2));
|
||||
ret = g_dbus_connection_close_sync (c2, NULL, &error);
|
||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED);
|
||||
g_error_free (error);
|
||||
g_assert (!ret);
|
||||
g_assert_false (ret);
|
||||
g_object_unref (c2);
|
||||
|
||||
/*
|
||||
@@ -205,7 +205,7 @@ test_connection_life_cycle (void)
|
||||
error = NULL;
|
||||
c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (c2 != NULL);
|
||||
g_assert_nonnull (c2);
|
||||
/* signal registration */
|
||||
on_signal_registration_freed_called = FALSE;
|
||||
g_dbus_connection_signal_subscribe (c2,
|
||||
@@ -235,7 +235,7 @@ test_connection_life_cycle (void)
|
||||
a_gdestroynotify_that_sets_a_gboolean_to_true_and_quits_loop,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (registration_id > 0);
|
||||
g_assert_cmpuint (registration_id, >, 0);
|
||||
/* ok, finalize the connection and check that all the GDestroyNotify functions are invoked as expected */
|
||||
g_object_unref (c2);
|
||||
quit_mainloop_fired = FALSE;
|
||||
@@ -260,20 +260,20 @@ test_connection_life_cycle (void)
|
||||
_log ("exiting loop");
|
||||
}
|
||||
g_source_remove (quit_mainloop_id);
|
||||
g_assert (on_signal_registration_freed_called);
|
||||
g_assert (on_filter_freed_called);
|
||||
g_assert (on_register_object_freed_called);
|
||||
g_assert (!quit_mainloop_fired);
|
||||
g_assert_true (on_signal_registration_freed_called);
|
||||
g_assert_true (on_filter_freed_called);
|
||||
g_assert_true (on_register_object_freed_called);
|
||||
g_assert_false (quit_mainloop_fired);
|
||||
|
||||
/*
|
||||
* Check for correct behavior when the bus goes away
|
||||
*
|
||||
*/
|
||||
g_assert (!g_dbus_connection_is_closed (c));
|
||||
g_assert_false (g_dbus_connection_is_closed (c));
|
||||
g_dbus_connection_set_exit_on_close (c, FALSE);
|
||||
session_bus_stop ();
|
||||
_g_assert_signal_received (c, "closed");
|
||||
g_assert (g_dbus_connection_is_closed (c));
|
||||
g_assert_true (g_dbus_connection_is_closed (c));
|
||||
g_object_unref (c);
|
||||
|
||||
session_bus_down ();
|
||||
@@ -299,9 +299,9 @@ msg_cb_expect_error_disconnected (GDBusConnection *connection,
|
||||
res,
|
||||
&error);
|
||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED);
|
||||
g_assert (!g_dbus_error_is_remote_error (error));
|
||||
g_assert_false (g_dbus_error_is_remote_error (error));
|
||||
g_error_free (error);
|
||||
g_assert (result == NULL);
|
||||
g_assert_null (result);
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
@@ -322,9 +322,9 @@ msg_cb_expect_error_unknown_method (GDBusConnection *connection,
|
||||
res,
|
||||
&error);
|
||||
g_assert_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD);
|
||||
g_assert (g_dbus_error_is_remote_error (error));
|
||||
g_assert_true (g_dbus_error_is_remote_error (error));
|
||||
g_error_free (error);
|
||||
g_assert (result == NULL);
|
||||
g_assert_null (result);
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
@@ -345,7 +345,7 @@ msg_cb_expect_success (GDBusConnection *connection,
|
||||
res,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (result != NULL);
|
||||
g_assert_nonnull (result);
|
||||
g_variant_unref (result);
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
@@ -367,9 +367,9 @@ msg_cb_expect_error_cancelled (GDBusConnection *connection,
|
||||
res,
|
||||
&error);
|
||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
|
||||
g_assert (!g_dbus_error_is_remote_error (error));
|
||||
g_assert_false (g_dbus_error_is_remote_error (error));
|
||||
g_error_free (error);
|
||||
g_assert (result == NULL);
|
||||
g_assert_null (result);
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
@@ -390,9 +390,9 @@ msg_cb_expect_error_cancelled_2 (GDBusConnection *connection,
|
||||
res,
|
||||
&error);
|
||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
|
||||
g_assert (!g_dbus_error_is_remote_error (error));
|
||||
g_assert_false (g_dbus_error_is_remote_error (error));
|
||||
g_error_free (error);
|
||||
g_assert (result == NULL);
|
||||
g_assert_null (result);
|
||||
|
||||
g_main_loop_quit (loop);
|
||||
}
|
||||
@@ -409,8 +409,8 @@ test_connection_send (void)
|
||||
|
||||
/* First, get an unopened connection */
|
||||
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
g_assert (c != NULL);
|
||||
g_assert (!g_dbus_connection_is_closed (c));
|
||||
g_assert_nonnull (c);
|
||||
g_assert_false (g_dbus_connection_is_closed (c));
|
||||
|
||||
/*
|
||||
* Check that we never actually send a message if the GCancellable
|
||||
@@ -490,7 +490,7 @@ test_connection_send (void)
|
||||
g_dbus_connection_set_exit_on_close (c, FALSE);
|
||||
session_bus_stop ();
|
||||
_g_assert_signal_received (c, "closed");
|
||||
g_assert (g_dbus_connection_is_closed (c));
|
||||
g_assert_true (g_dbus_connection_is_closed (c));
|
||||
|
||||
g_dbus_connection_call (c,
|
||||
"org.freedesktop.DBus", /* bus_name */
|
||||
@@ -567,13 +567,13 @@ test_connection_signals (void)
|
||||
if (g_getenv ("G_DBUS_MONITOR") == NULL)
|
||||
{
|
||||
c1 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
g_assert (c1 != NULL);
|
||||
g_assert (!g_dbus_connection_is_closed (c1));
|
||||
g_assert_nonnull (c1);
|
||||
g_assert_false (g_dbus_connection_is_closed (c1));
|
||||
g_object_unref (c1);
|
||||
}
|
||||
c1 = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
g_assert (c1 != NULL);
|
||||
g_assert (!g_dbus_connection_is_closed (c1));
|
||||
g_assert_nonnull (c1);
|
||||
g_assert_false (g_dbus_connection_is_closed (c1));
|
||||
g_assert_cmpstr (g_dbus_connection_get_unique_name (c1), ==, ":1.1");
|
||||
|
||||
/*
|
||||
@@ -628,10 +628,10 @@ test_connection_signals (void)
|
||||
test_connection_signal_handler,
|
||||
&count_s1b,
|
||||
NULL);
|
||||
g_assert (s1 != 0);
|
||||
g_assert (s1b != 0);
|
||||
g_assert (s2 != 0);
|
||||
g_assert (s3 != 0);
|
||||
g_assert_cmpuint (s1, !=, 0);
|
||||
g_assert_cmpuint (s1b, !=, 0);
|
||||
g_assert_cmpuint (s2, !=, 0);
|
||||
g_assert_cmpuint (s3, !=, 0);
|
||||
|
||||
count_s1 = 0;
|
||||
count_s1b = 0;
|
||||
@@ -661,19 +661,19 @@ test_connection_signals (void)
|
||||
NULL,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (result != NULL);
|
||||
g_assert_nonnull (result);
|
||||
g_variant_unref (result);
|
||||
|
||||
/*
|
||||
* Bring up two other connections
|
||||
*/
|
||||
c2 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
g_assert (c2 != NULL);
|
||||
g_assert (!g_dbus_connection_is_closed (c2));
|
||||
g_assert_nonnull (c2);
|
||||
g_assert_false (g_dbus_connection_is_closed (c2));
|
||||
g_assert_cmpstr (g_dbus_connection_get_unique_name (c2), ==, ":1.2");
|
||||
c3 = _g_bus_get_priv (G_BUS_TYPE_SESSION, NULL, NULL);
|
||||
g_assert (c3 != NULL);
|
||||
g_assert (!g_dbus_connection_is_closed (c3));
|
||||
g_assert_nonnull (c3);
|
||||
g_assert_false (g_dbus_connection_is_closed (c3));
|
||||
g_assert_cmpstr (g_dbus_connection_get_unique_name (c3), ==, ":1.3");
|
||||
|
||||
/* now, emit the signal on c2 */
|
||||
@@ -685,7 +685,7 @@ test_connection_signals (void)
|
||||
NULL,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret);
|
||||
g_assert_true (ret);
|
||||
while (!(count_s1 >= 1 && count_s2 >= 1))
|
||||
g_main_loop_run (loop);
|
||||
g_assert_cmpint (count_s1, ==, 1);
|
||||
@@ -702,7 +702,7 @@ test_connection_signals (void)
|
||||
NULL,
|
||||
&error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (ret);
|
||||
g_assert_true (ret);
|
||||
while (!(count_s1 == 1 && count_s2 == 2))
|
||||
g_main_loop_run (loop);
|
||||
g_assert_cmpint (count_s1, ==, 1);
|
||||
@@ -947,7 +947,7 @@ test_connection_filter (void)
|
||||
error = NULL;
|
||||
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (c != NULL);
|
||||
g_assert_nonnull (c);
|
||||
|
||||
filter_id = g_dbus_connection_add_filter (c,
|
||||
filter_func,
|
||||
@@ -998,7 +998,7 @@ test_connection_filter (void)
|
||||
&error);
|
||||
g_object_unref (m2);
|
||||
g_assert_no_error (error);
|
||||
g_assert (r != NULL);
|
||||
g_assert_nonnull (r);
|
||||
g_object_unref (r);
|
||||
g_assert_cmpint (data.num_handled, ==, 4);
|
||||
|
||||
@@ -1015,7 +1015,7 @@ test_connection_filter (void)
|
||||
&error);
|
||||
g_object_unref (m2);
|
||||
g_assert_no_error (error);
|
||||
g_assert (r != NULL);
|
||||
g_assert_nonnull (r);
|
||||
g_object_unref (r);
|
||||
g_assert_cmpint (data.num_handled, ==, 4);
|
||||
g_assert_cmpint (data.num_outgoing, ==, 4);
|
||||
@@ -1034,7 +1034,7 @@ test_connection_filter (void)
|
||||
g_assert_cmpint (signal_handler_id, !=, 0);
|
||||
|
||||
/* this is safe; testserver will exit once the bus goes away */
|
||||
g_assert (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
|
||||
g_assert_true (g_spawn_command_line_async (g_test_get_filename (G_TEST_BUILT, "gdbus-testserver", NULL), NULL));
|
||||
|
||||
timeout_mainloop_id = g_timeout_add (30000, test_connection_filter_on_timeout, NULL);
|
||||
g_main_loop_run (loop);
|
||||
@@ -1159,7 +1159,7 @@ test_connection_serials (void)
|
||||
error = NULL;
|
||||
c = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (c != NULL);
|
||||
g_assert_nonnull (c);
|
||||
|
||||
/* Status after initialization */
|
||||
g_assert_cmpint (g_dbus_connection_get_last_serial (c), ==, 1);
|
||||
@@ -1210,11 +1210,11 @@ test_connection_basic (void)
|
||||
error = NULL;
|
||||
connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (connection != NULL);
|
||||
g_assert_nonnull (connection);
|
||||
|
||||
flags = g_dbus_connection_get_capabilities (connection);
|
||||
g_assert (flags == G_DBUS_CAPABILITY_FLAGS_NONE ||
|
||||
flags == G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
|
||||
g_assert_true (flags == G_DBUS_CAPABILITY_FLAGS_NONE ||
|
||||
flags == G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
|
||||
|
||||
connection_flags = g_dbus_connection_get_flags (connection);
|
||||
g_assert_cmpint (connection_flags, ==,
|
||||
@@ -1222,7 +1222,7 @@ test_connection_basic (void)
|
||||
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION);
|
||||
|
||||
credentials = g_dbus_connection_get_peer_credentials (connection);
|
||||
g_assert (credentials == NULL);
|
||||
g_assert_null (credentials);
|
||||
|
||||
g_object_get (connection,
|
||||
"stream", &stream,
|
||||
@@ -1233,13 +1233,13 @@ test_connection_basic (void)
|
||||
"capabilities", &flags,
|
||||
NULL);
|
||||
|
||||
g_assert (G_IS_IO_STREAM (stream));
|
||||
g_assert (g_dbus_is_guid (guid));
|
||||
g_assert (g_dbus_is_unique_name (name));
|
||||
g_assert (!closed);
|
||||
g_assert (exit_on_close);
|
||||
g_assert (flags == G_DBUS_CAPABILITY_FLAGS_NONE ||
|
||||
flags == G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
|
||||
g_assert_true (G_IS_IO_STREAM (stream));
|
||||
g_assert_true (g_dbus_is_guid (guid));
|
||||
g_assert_true (g_dbus_is_unique_name (name));
|
||||
g_assert_false (closed);
|
||||
g_assert_true (exit_on_close);
|
||||
g_assert_true (flags == G_DBUS_CAPABILITY_FLAGS_NONE ||
|
||||
flags == G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING);
|
||||
g_object_unref (stream);
|
||||
g_free (name);
|
||||
g_free (guid);
|
||||
|
Reference in New Issue
Block a user