From c93990ce8ef79e569e7d70b5ed6c29090bb33b5c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 26 Mar 2021 11:15:41 +0000 Subject: 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 --- dbus/dbus-gvalue.c | 2 +- test/core/error-mapping.c | 6 ++--- test/core/manual/invalid-usage.c | 8 +++--- test/core/peer-client.c | 2 +- test/core/peer-on-bus.c | 4 +-- test/core/private.c | 2 +- test/core/proxy-noc.c | 6 ++--- test/core/proxy-peer.c | 8 +++--- test/core/registrations.c | 12 ++++----- test/core/shared-bus.c | 4 +-- test/core/test-dbus-glib.c | 56 ++++++++++++++++++++-------------------- test/core/test-service-glib.c | 2 +- test/errors.c | 2 +- test/interfaces/test-client.c | 2 +- test/specialized-types.c | 2 +- 15 files changed, 59 insertions(+), 59 deletions(-) diff --git a/dbus/dbus-gvalue.c b/dbus/dbus-gvalue.c index 5bb2b19..7220f50 100644 --- a/dbus/dbus-gvalue.c +++ b/dbus/dbus-gvalue.c @@ -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); } diff --git a/test/core/error-mapping.c b/test/core/error-mapping.c index 84837fd..764275f 100644 --- a/test/core/error-mapping.c +++ b/test/core/error-mapping.c @@ -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); diff --git a/test/core/manual/invalid-usage.c b/test/core/manual/invalid-usage.c index 6ca4b1f..8d3302a 100644 --- a/test/core/manual/invalid-usage.c +++ b/test/core/manual/invalid-usage.c @@ -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); } diff --git a/test/core/peer-client.c b/test/core/peer-client.c index 836f6c4..a81c364 100644 --- a/test/core/peer-client.c +++ b/test/core/peer-client.c @@ -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)) diff --git a/test/core/peer-on-bus.c b/test/core/peer-on-bus.c index 4a62420..87ff2d8 100644 --- a/test/core/peer-on-bus.c +++ b/test/core/peer-on-bus.c @@ -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 diff --git a/test/core/private.c b/test/core/private.c index b37ae20..7969ce8 100644 --- a/test/core/private.c +++ b/test/core/private.c @@ -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)); diff --git a/test/core/proxy-noc.c b/test/core/proxy-noc.c index 3f10eb3..d6a026a 100644 --- a/test/core/proxy-noc.c +++ b/test/core/proxy-noc.c @@ -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, diff --git a/test/core/proxy-peer.c b/test/core/proxy-peer.c index b225d94..6cead4e 100644 --- a/test/core/proxy-peer.c +++ b/test/core/proxy-peer.c @@ -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) diff --git a/test/core/registrations.c b/test/core/registrations.c index 2c32e5a..3b2d01b 100644 --- a/test/core/registrations.c +++ b/test/core/registrations.c @@ -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 ( diff --git a/test/core/shared-bus.c b/test/core/shared-bus.c index 0f18880..a69094d 100644 --- a/test/core/shared-bus.c +++ b/test/core/shared-bus.c @@ -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); diff --git a/test/core/test-dbus-glib.c b/test/core/test-dbus-glib.c index 4e050b2..0910ccb 100644 --- a/test/core/test-dbus-glib.c +++ b/test/core/test-dbus-glib.c @@ -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); diff --git a/test/core/test-service-glib.c b/test/core/test-service-glib.c index 8712b17..1b328f7 100644 --- a/test/core/test-service-glib.c +++ b/test/core/test-service-glib.c @@ -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); diff --git a/test/errors.c b/test/errors.c index 468dec7..cf2110e 100644 --- a/test/errors.c +++ b/test/errors.c @@ -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!"); diff --git a/test/interfaces/test-client.c b/test/interfaces/test-client.c index b2d0104..8fc60a0 100644 --- a/test/interfaces/test-client.c +++ b/test/interfaces/test-client.c @@ -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); diff --git a/test/specialized-types.c b/test/specialized-types.c index 7c8b0ed..e0e743a 100644 --- a/test/specialized-types.c +++ b/test/specialized-types.c @@ -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)); -- cgit v1.2.1