Commit c93990ce authored by Simon McVittie's avatar Simon McVittie
Browse files

test: Replace all g_assert (x != NULL) with g_assert_nonnull (x)



This avoids the assertions being removed by G_DISABLE_ASSERT, and gives
somewhat better diagnostic messages if the assertion fails.

Signed-off-by: Simon McVittie's avatarSimon McVittie <smcv@collabora.com>
parent 06a7fac3
......@@ -2028,7 +2028,7 @@ assert_type_maps_to (GType gtype, const char *expected_sig)
{
char *sig;
sig = _dbus_gtype_to_signature (gtype);
g_assert (sig != NULL);
g_assert_nonnull (sig);
g_assert (!strcmp (expected_sig, sig));
g_free (sig);
}
......
......@@ -88,7 +88,7 @@ setup (Fixture *f,
f->conn = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, &f->error);
g_assert_no_error (f->error);
g_assert (f->conn != NULL);
g_assert_nonnull (f->conn);
f->object = g_object_new (MY_TYPE_OBJECT, NULL);
g_assert (MY_IS_OBJECT (f->object));
......@@ -98,7 +98,7 @@ setup (Fixture *f,
f->proxy = dbus_g_proxy_new_for_name (f->conn,
dbus_bus_get_unique_name (dbus_g_connection_get_connection (f->conn)),
"/com/example/Test/Object", "org.freedesktop.DBus.GLib.Tests.MyObject");
g_assert (f->proxy != NULL);
g_assert_nonnull (f->proxy);
}
static void
......@@ -108,7 +108,7 @@ throw_error_cb (DBusGProxy *proxy,
{
Fixture *f = user_data;
g_assert (error != NULL);
g_assert_nonnull (error);
g_clear_error (&f->error);
g_free (f->error_name);
f->error = g_error_copy (error);
......
......@@ -68,11 +68,11 @@ setup (Fixture *f,
f->conn = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, &f->error);
g_assert_no_error (f->error);
g_assert (f->conn != NULL);
g_assert_nonnull (f->conn);
f->proxy = dbus_g_proxy_new_for_name (f->conn, "com.example.Test",
"/com/example/Test/Object", "com.example.Test.Fallible");
g_assert (f->proxy != NULL);
g_assert_nonnull (f->proxy);
f->object = g_object_new (MY_TYPE_OBJECT, NULL);
g_assert (MY_IS_OBJECT (f->object));
......@@ -82,7 +82,7 @@ setup (Fixture *f,
f->proxy_for_self = dbus_g_proxy_new_for_name (f->conn,
dbus_bus_get_unique_name (dbus_g_connection_get_connection (f->conn)),
"/com/example/Test/Object", "org.freedesktop.DBus.GLib.Tests.MyObject");
g_assert (f->proxy_for_self != NULL);
g_assert_nonnull (f->proxy_for_self);
}
static void
......@@ -194,7 +194,7 @@ throw_error_cb (DBusGProxy *proxy,
{
GError **error_out = user_data;
g_assert (error != NULL);
g_assert_nonnull (error);
*error_out = g_error_copy (error);
}
......
......@@ -95,7 +95,7 @@ main (int argc, char **argv)
g_error ("Cannot open connection: %s", error->message);
proxy = dbus_g_proxy_new_for_peer (conn, "/", "org.freedesktop.DBus.GLib.Tests.MyObject");
g_assert (proxy);
g_assert_nonnull (proxy);
if (!dbus_g_proxy_call (proxy, "DoNothing", &error, G_TYPE_INVALID, G_TYPE_INVALID))
......
......@@ -56,10 +56,10 @@ setup (Fixture *f,
gconstpointer path_to_use)
{
f->bus = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, NULL);
g_assert (f->bus != NULL);
g_assert_nonnull (f->bus);
f->bus2 = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, NULL);
g_assert (f->bus2 != NULL);
g_assert_nonnull (f->bus2);
}
static void
......
......@@ -91,7 +91,7 @@ setup (Fixture *f,
f->in_flight = 0;
f->bus = dbus_g_bus_get_private (DBUS_BUS_SESSION, f->context, NULL);
g_assert (f->bus != NULL);
g_assert_nonnull (f->bus);
f->object = g_object_new (MY_TYPE_OBJECT, NULL);
g_assert (MY_IS_OBJECT (f->object));
......
......@@ -101,14 +101,14 @@ setup (Fixture *f,
f->service_gconn = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL,
&f->error);
g_assert_no_error (f->error);
g_assert (f->service_gconn != NULL);
g_assert_nonnull (f->service_gconn);
f->service_conn = dbus_g_connection_get_connection (f->service_gconn);
/* An attacker that intends to pretend to be that service. */
f->attacker_gconn = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL,
&f->error);
g_assert_no_error (f->error);
g_assert (f->attacker_gconn != NULL);
g_assert_nonnull (f->attacker_gconn);
f->attacker_conn = dbus_g_connection_get_connection (f->attacker_gconn);
/* The service owns a well-known name. */
......@@ -120,7 +120,7 @@ setup (Fixture *f,
/* The victim of the attack. */
f->client_gconn = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, &f->error);
g_assert_no_error (f->error);
g_assert (f->client_gconn != NULL);
g_assert_nonnull (f->client_gconn);
f->client_conn = dbus_g_connection_get_connection (f->client_gconn);
f->proxy = dbus_g_proxy_new_for_name (f->client_gconn, WELL_KNOWN_NAME,
......
......@@ -94,7 +94,7 @@ setup (Fixture *f,
f->server = dbus_server_listen (addr, &f->e);
assert_no_error (&f->e);
g_assert (f->server != NULL);
g_assert_nonnull (f->server);
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
......@@ -105,7 +105,7 @@ setup (Fixture *f,
f->client_conn = dbus_connection_open_private (
dbus_server_get_address (f->server), &f->e);
assert_no_error (&f->e);
g_assert (f->client_conn != NULL);
g_assert_nonnull (f->client_conn);
dbus_connection_setup_with_g_main (f->client_conn, NULL);
f->client_gconn = dbus_connection_get_g_connection (f->client_conn);
......@@ -123,7 +123,7 @@ setup (Fixture *f,
f->proxy = dbus_g_proxy_new_for_peer (f->client_gconn,
"/org/freedesktop/DBus/GLib/Tests/MyTestObject",
"org.freedesktop.DBus.GLib.Tests.MyObject");
g_assert (f->proxy != NULL);
g_assert_nonnull (f->proxy);
g_assert (DBUS_IS_G_PROXY (f->proxy));
g_signal_connect (f->proxy, "destroy", G_CALLBACK (destroy_cb), f);
......@@ -155,7 +155,7 @@ test_method (Fixture *f,
call = dbus_g_proxy_begin_call (f->proxy, "DoNothing", call_cb, f, NULL,
G_TYPE_INVALID);
g_assert (call != NULL);
g_assert_nonnull (call);
g_hash_table_insert (f->in_flight, call, call);
while (g_hash_table_size (f->in_flight) > 0)
......
......@@ -76,10 +76,10 @@ setup (Fixture *f,
dbus_error_init (&f->dbus_error);
f->bus = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, NULL);
g_assert (f->bus != NULL);
g_assert_nonnull (f->bus);
f->bus2 = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, NULL);
g_assert (f->bus2 != NULL);
g_assert_nonnull (f->bus2);
f->object = g_object_new (MY_TYPE_OBJECT, NULL);
g_assert (MY_IS_OBJECT (f->object));
......@@ -214,8 +214,8 @@ frobnicate_cb (DBusConnection *conn,
const char *sender = dbus_message_get_sender (message);
const char *path = dbus_message_get_path (message);
g_assert (sender != NULL);
g_assert (path != NULL);
g_assert_nonnull (sender);
g_assert_nonnull (path);
if (g_strcmp0 (path, "/foo") == 0)
{
......@@ -368,8 +368,8 @@ objectified_cb (DBusConnection *conn,
dbus_error_init (&e);
g_assert (sender != NULL);
g_assert (path != NULL);
g_assert_nonnull (sender);
g_assert_nonnull (path);
g_assert_cmpstr (path, ==, "/foo");
g_assert_cmpstr (sender, ==, dbus_bus_get_unique_name (
......
......@@ -106,7 +106,7 @@ test_shared_bus (Fixture *f,
{
f->bus = dbus_g_bus_get (DBUS_BUS_SESSION, &f->error);
g_assert_no_error (f->error);
g_assert (f->bus != NULL);
g_assert_nonnull (f->bus);
dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (f->bus),
FALSE);
......@@ -116,7 +116,7 @@ test_shared_bus (Fixture *f,
f->priv = dbus_g_bus_get_private (DBUS_BUS_SESSION, NULL, &f->error);
g_assert_no_error (f->error);
g_assert (f->priv != NULL);
g_assert_nonnull (f->priv);
g_assert (f->priv != f->bus);
dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (f->priv),
FALSE);
......
......@@ -251,9 +251,9 @@ sig2_signal_handler (DBusGProxy *proxy,
g_assert (g_hash_table_size (table) == 2);
g_assert (g_hash_table_lookup (table, "baz") != NULL);
g_assert_nonnull (g_hash_table_lookup (table, "baz"));
g_assert (!strcmp (g_hash_table_lookup (table, "baz"), "cow"));
g_assert (g_hash_table_lookup (table, "bar") != NULL);
g_assert_nonnull (g_hash_table_lookup (table, "bar"));
g_assert (!strcmp (g_hash_table_lookup (table, "bar"), "foo"));
g_print ("Got Sig2 signal\n");
......@@ -284,7 +284,7 @@ echo_received_cb (DBusGProxy *proxy,
&echo_data,
G_TYPE_INVALID))
lose_gerror ("Failed to complete async Echo", error);
g_assert (echo_data != NULL);
g_assert_nonnull (echo_data);
g_print ("Async echo gave \"%s\"\n", echo_data);
g_free (echo_data);
g_main_loop_quit (loop);
......@@ -343,8 +343,8 @@ test_base_class_get_all (DBusGConnection *connection,
/* g_test_bug (19145); */
g_assert (expected_string_value != NULL);
g_assert (object_path != NULL);
g_assert_nonnull (expected_string_value);
g_assert_nonnull (object_path);
/* Test GetAll with interfaces on the base class */
......@@ -352,7 +352,7 @@ test_base_class_get_all (DBusGConnection *connection,
"org.freedesktop.DBus.GLib.TestService",
object_path,
DBUS_INTERFACE_PROPERTIES);
g_assert (proxy != NULL);
g_assert_nonnull (proxy);
g_print ("%s: Calling GetAll for unknown interface\n", object_path);
{
......@@ -434,7 +434,7 @@ test_subclass_get_all (DBusGConnection *connection,
/* g_test_bug (19145); */
g_assert (object_path != NULL);
g_assert_nonnull (object_path);
/* Test GetAll with interfaces on the subclass */
......@@ -442,7 +442,7 @@ test_subclass_get_all (DBusGConnection *connection,
"org.freedesktop.DBus.GLib.TestService",
object_path,
DBUS_INTERFACE_PROPERTIES);
g_assert (proxy != NULL);
g_assert_nonnull (proxy);
g_print ("%s: Calling GetAll for subclass interface\n", object_path);
{
......@@ -600,7 +600,7 @@ main (int argc, char **argv)
name_list_len = g_strv_length (name_list);
while (i < name_list_len)
{
g_assert (name_list[i] != NULL);
g_assert_nonnull (name_list[i]);
g_print (" %s\n", name_list[i]);
++i;
}
......@@ -1112,7 +1112,7 @@ main (int argc, char **argv)
g_print ("Calling (wrapped) many_uppercase\n");
if (!org_freedesktop_DBus_GLib_Tests_MyObject_many_uppercase (proxy, strs, &strs_ret, &error))
lose_gerror ("Failed to complete (wrapped) ManyUppercase call", error);
g_assert (strs_ret != NULL);
g_assert_nonnull (strs_ret);
if (strcmp ("HELLO", strs_ret[0]) != 0)
lose ("(wrapped) ManyUppercase call returned unexpected string %s", strs_ret[0]);
if (strcmp ("HELLO", strs_ret[1]) != 0)
......@@ -1199,7 +1199,7 @@ main (int argc, char **argv)
G_TYPE_INVALID))
lose_gerror ("Failed to complete SendCar call", error);
g_assert (vals_ret != NULL);
g_assert_nonnull (vals_ret);
g_assert (vals_ret->n_values == 2);
g_assert (G_VALUE_HOLDS_UINT (g_value_array_get_nth (vals_ret, 0)));
......@@ -1260,16 +1260,16 @@ main (int argc, char **argv)
G_TYPE_INVALID))
lose_gerror ("Failed to complete ManyStringify call", error);
g_assert (ret_table != NULL);
g_assert_nonnull (ret_table);
g_assert (g_hash_table_size (ret_table) == 2);
val = g_hash_table_lookup (ret_table, "foo");
g_assert (val != NULL);
g_assert_nonnull (val);
g_assert (G_VALUE_HOLDS_STRING (val));
g_assert (!strcmp ("42", g_value_get_string (val)));
val = g_hash_table_lookup (ret_table, "bar");
g_assert (val != NULL);
g_assert_nonnull (val);
g_assert (G_VALUE_HOLDS_STRING (val));
g_assert (!strcmp ("hello", g_value_get_string (val)));
......@@ -1312,17 +1312,17 @@ main (int argc, char **argv)
g_free (g_ptr_array_index (in_array, 1));
g_ptr_array_free (in_array, TRUE);
g_assert (out_array);
g_assert_nonnull (out_array);
g_assert (out_array->len == 2);
uints = g_ptr_array_index (out_array, 0);
g_assert (uints);
g_assert_nonnull (uints);
g_assert (uints->len == 3);
g_assert (g_array_index (uints, guint, 0) == 10);
g_assert (g_array_index (uints, guint, 1) == 42);
g_assert (g_array_index (uints, guint, 2) == 27);
g_array_free (uints, TRUE);
uints = g_ptr_array_index (out_array, 1);
g_assert (uints);
g_assert_nonnull (uints);
g_assert (uints->len == 1);
g_assert (g_array_index (uints, guint, 0) == 30);
g_array_free (uints, TRUE);
......@@ -1520,39 +1520,39 @@ main (int argc, char **argv)
G_TYPE_INVALID))
lose_gerror ("Failed to complete DictOfDicts call", error);
g_assert (ret_table != NULL);
g_assert_nonnull (ret_table);
g_assert (g_hash_table_size (ret_table) == 2);
subtable = g_hash_table_lookup (ret_table, "dict1");
g_assert(subtable);
g_assert_nonnull (subtable);
g_assert (g_hash_table_size (subtable) == 3);
val = g_hash_table_lookup (subtable, "foo");
g_assert (val != NULL);
g_assert_nonnull (val);
g_assert (!strcmp ("dict1 1", val));
val = g_hash_table_lookup (subtable, "bar");
g_assert (val != NULL);
g_assert_nonnull (val);
g_assert (!strcmp ("dict1 2", val));
val = g_hash_table_lookup (subtable, "baz");
g_assert (val != NULL);
g_assert_nonnull (val);
g_assert (!strcmp ("dict1 3", val));
subtable = g_hash_table_lookup (ret_table, "dict2");
g_assert(subtable);
g_assert_nonnull (subtable);
g_assert (g_hash_table_size (subtable) == 3);
val = g_hash_table_lookup (subtable, "foo");
g_assert (val != NULL);
g_assert_nonnull (val);
g_assert (!strcmp ("dict2 4", val));
val = g_hash_table_lookup (subtable, "bar");
g_assert (val != NULL);
g_assert_nonnull (val);
g_assert (!strcmp ("dict2 5", val));
val = g_hash_table_lookup (subtable, "baz");
g_assert (val != NULL);
g_assert_nonnull (val);
g_assert (!strcmp ("dict2 6", val));
g_hash_table_destroy (table);
......@@ -1809,7 +1809,7 @@ main (int argc, char **argv)
"org.freedesktop.DBus.GLib.TestService",
"/org/freedesktop/DBus/GLib/Tests/MyTestObject",
"org.freedesktop.DBus.GLib.Tests.MyObject");
g_assert (proxy != NULL);
g_assert_nonnull (proxy);
proxy_destroyed = FALSE;
proxy_destroy_and_nameowner = FALSE;
......@@ -1912,7 +1912,7 @@ main (int argc, char **argv)
"org.freedesktop.DBus.GLib.TestService",
"/org/freedesktop/DBus/GLib/Tests/MyTestObject",
"org.freedesktop.DBus.GLib.Tests.MyObject");
g_assert (proxy2 != NULL);
g_assert_nonnull (proxy2);
dbus_g_proxy_add_signal (proxy2, "Frobnicate", G_TYPE_INT, G_TYPE_INVALID);
......
......@@ -90,7 +90,7 @@ main (int argc, char **argv)
TEST_SERVICE_NAME,
0, &request_name_ret, &error))
{
g_assert (error != NULL);
g_assert_nonnull (error);
g_printerr ("Failed to get name: %s\n",
error->message);
g_clear_error (&error);
......
......@@ -53,7 +53,7 @@ test_errors (Fixture *f G_GNUC_UNUSED,
dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!");
dbus_set_g_error (&gerror, &err);
g_assert (gerror != NULL);
g_assert_nonnull (gerror);
g_assert_error (gerror, DBUS_GERROR, DBUS_GERROR_NO_MEMORY);
g_assert_cmpstr (gerror->message, ==, "Out of memory!");
......
......@@ -134,7 +134,7 @@ main (int argc,
proxy = dbus_g_proxy_new_for_name (connection, TEST_NAMESPACE, TEST_OBJECT_PATH,
"org.freedesktop.DBus.GLib.Test.Interfaces.Hello");
g_assert (proxy != NULL);
g_assert_nonnull (proxy);
success = org_freedesktop_DBus_GLib_Test_Interfaces_Hello_say_hello (proxy, &str, &error);
g_object_unref (proxy);
......
......@@ -246,7 +246,7 @@ test_ao_slist (Fixture *f G_GNUC_UNUSED,
GValue eltval = { 0, };
GObject *obj = g_object_new (G_TYPE_OBJECT, NULL);
g_assert (obj != NULL);
g_assert_nonnull (obj);
objects[i] = obj;
g_object_add_weak_pointer (obj, (gpointer) (objects + i));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment