mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-11 23:16:14 +01:00
tests: Tidy up GError handling in gdbus-serialization test
This introduces no functional changes; just a bit of code tidying. Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
parent
5f3b393662
commit
c2c9c7fa3b
@ -857,7 +857,7 @@ message_serialize_header_checks (void)
|
|||||||
{
|
{
|
||||||
GDBusMessage *message;
|
GDBusMessage *message;
|
||||||
GDBusMessage *reply;
|
GDBusMessage *reply;
|
||||||
GError *error;
|
GError *error = NULL;
|
||||||
guchar *blob;
|
guchar *blob;
|
||||||
gsize blob_size;
|
gsize blob_size;
|
||||||
|
|
||||||
@ -865,11 +865,10 @@ message_serialize_header_checks (void)
|
|||||||
* check we can't serialize messages with INVALID type
|
* check we can't serialize messages with INVALID type
|
||||||
*/
|
*/
|
||||||
message = g_dbus_message_new ();
|
message = g_dbus_message_new ();
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: type is INVALID");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: type is INVALID");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
g_object_unref (message);
|
g_object_unref (message);
|
||||||
|
|
||||||
@ -894,49 +893,44 @@ message_serialize_header_checks (void)
|
|||||||
/* ----- */
|
/* ----- */
|
||||||
/* interface NULL => error */
|
/* interface NULL => error */
|
||||||
g_dbus_message_set_interface (message, NULL);
|
g_dbus_message_set_interface (message, NULL);
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
/* interface reserved value => error */
|
/* interface reserved value => error */
|
||||||
g_dbus_message_set_interface (message, "org.freedesktop.DBus.Local");
|
g_dbus_message_set_interface (message, "org.freedesktop.DBus.Local");
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: The INTERFACE header field is using the reserved value org.freedesktop.DBus.Local");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: The INTERFACE header field is using the reserved value org.freedesktop.DBus.Local");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
/* reset interface */
|
/* reset interface */
|
||||||
g_dbus_message_set_interface (message, "The.Interface");
|
g_dbus_message_set_interface (message, "The.Interface");
|
||||||
/* ----- */
|
/* ----- */
|
||||||
/* path NULL => error */
|
/* path NULL => error */
|
||||||
g_dbus_message_set_path (message, NULL);
|
g_dbus_message_set_path (message, NULL);
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
/* path reserved value => error */
|
/* path reserved value => error */
|
||||||
g_dbus_message_set_path (message, "/org/freedesktop/DBus/Local");
|
g_dbus_message_set_path (message, "/org/freedesktop/DBus/Local");
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: The PATH header field is using the reserved value /org/freedesktop/DBus/Local");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: The PATH header field is using the reserved value /org/freedesktop/DBus/Local");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
/* reset path */
|
/* reset path */
|
||||||
g_dbus_message_set_path (message, "/the/path");
|
g_dbus_message_set_path (message, "/the/path");
|
||||||
/* ----- */
|
/* ----- */
|
||||||
/* member NULL => error */
|
/* member NULL => error */
|
||||||
g_dbus_message_set_member (message, NULL);
|
g_dbus_message_set_member (message, NULL);
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: SIGNAL message: PATH, INTERFACE or MEMBER header field is missing");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
/* reset member */
|
/* reset member */
|
||||||
g_dbus_message_set_member (message, "TheMember");
|
g_dbus_message_set_member (message, "TheMember");
|
||||||
@ -951,22 +945,20 @@ message_serialize_header_checks (void)
|
|||||||
/* ----- */
|
/* ----- */
|
||||||
/* path NULL => error */
|
/* path NULL => error */
|
||||||
g_dbus_message_set_path (message, NULL);
|
g_dbus_message_set_path (message, NULL);
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_CALL message: PATH or MEMBER header field is missing");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_CALL message: PATH or MEMBER header field is missing");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
/* reset path */
|
/* reset path */
|
||||||
g_dbus_message_set_path (message, "/the/path");
|
g_dbus_message_set_path (message, "/the/path");
|
||||||
/* ----- */
|
/* ----- */
|
||||||
/* member NULL => error */
|
/* member NULL => error */
|
||||||
g_dbus_message_set_member (message, NULL);
|
g_dbus_message_set_member (message, NULL);
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (message, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_CALL message: PATH or MEMBER header field is missing");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_CALL message: PATH or MEMBER header field is missing");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
/* reset member */
|
/* reset member */
|
||||||
g_dbus_message_set_member (message, "TheMember");
|
g_dbus_message_set_member (message, "TheMember");
|
||||||
@ -983,11 +975,10 @@ message_serialize_header_checks (void)
|
|||||||
reply = g_dbus_message_new_method_reply (message);
|
reply = g_dbus_message_new_method_reply (message);
|
||||||
g_assert_cmpint (g_dbus_message_get_reply_serial (reply), ==, 42);
|
g_assert_cmpint (g_dbus_message_get_reply_serial (reply), ==, 42);
|
||||||
g_dbus_message_set_header (reply, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL, NULL);
|
g_dbus_message_set_header (reply, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL, NULL);
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_RETURN message: REPLY_SERIAL header field is missing");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: METHOD_RETURN message: REPLY_SERIAL header field is missing");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
g_object_unref (reply);
|
g_object_unref (reply);
|
||||||
/* method error - first nuke ERROR_NAME, then REPLY_SERIAL */
|
/* method error - first nuke ERROR_NAME, then REPLY_SERIAL */
|
||||||
@ -995,21 +986,19 @@ message_serialize_header_checks (void)
|
|||||||
g_assert_cmpint (g_dbus_message_get_reply_serial (reply), ==, 42);
|
g_assert_cmpint (g_dbus_message_get_reply_serial (reply), ==, 42);
|
||||||
/* nuke ERROR_NAME */
|
/* nuke ERROR_NAME */
|
||||||
g_dbus_message_set_error_name (reply, NULL);
|
g_dbus_message_set_error_name (reply, NULL);
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: ERROR message: REPLY_SERIAL or ERROR_NAME header field is missing");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: ERROR message: REPLY_SERIAL or ERROR_NAME header field is missing");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
/* reset ERROR_NAME */
|
/* reset ERROR_NAME */
|
||||||
g_dbus_message_set_error_name (reply, "Some.Error.Name");
|
g_dbus_message_set_error_name (reply, "Some.Error.Name");
|
||||||
/* nuke REPLY_SERIAL */
|
/* nuke REPLY_SERIAL */
|
||||||
g_dbus_message_set_header (reply, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL, NULL);
|
g_dbus_message_set_header (reply, G_DBUS_MESSAGE_HEADER_FIELD_REPLY_SERIAL, NULL);
|
||||||
error = NULL;
|
|
||||||
blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
blob = g_dbus_message_to_blob (reply, &blob_size, G_DBUS_CAPABILITY_FLAGS_NONE, &error);
|
||||||
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT);
|
||||||
g_assert_cmpstr (error->message, ==, "Cannot serialize message: ERROR message: REPLY_SERIAL or ERROR_NAME header field is missing");
|
g_assert_cmpstr (error->message, ==, "Cannot serialize message: ERROR message: REPLY_SERIAL or ERROR_NAME header field is missing");
|
||||||
g_error_free (error);
|
g_clear_error (&error);
|
||||||
g_assert (blob == NULL);
|
g_assert (blob == NULL);
|
||||||
g_object_unref (reply);
|
g_object_unref (reply);
|
||||||
g_object_unref (message);
|
g_object_unref (message);
|
||||||
|
Loading…
Reference in New Issue
Block a user