Add some more test about gdbus_error apis

This commit is contained in:
Matthias Clasen 2010-08-07 18:55:21 -04:00
parent 7de6658f74
commit 8e236f7ec1

View File

@ -180,6 +180,76 @@ test_transparent_gerror (void)
check_transparent_gerror (G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_PARSE);
}
typedef enum
{
TEST_ERROR_FAILED,
TEST_ERROR_BLA
} TestError;
GDBusErrorEntry test_error_entries[] =
{
{ TEST_ERROR_FAILED, "org.gtk.test.Error.Failed" },
{ TEST_ERROR_BLA, "org.gtk.test.Error.Bla" }
};
static void
test_register_error (void)
{
gsize test_error_quark = 0;
gboolean res;
gchar *msg;
GError *error;
g_dbus_error_register_error_domain ("test-error-quark",
&test_error_quark,
test_error_entries,
G_N_ELEMENTS (test_error_entries));
g_assert_cmpint (test_error_quark, !=, 0);
error = g_dbus_error_new_for_dbus_error ("org.gtk.test.Error.Failed", "Failed");
g_assert_error (error, test_error_quark, TEST_ERROR_FAILED);
res = g_dbus_error_is_remote_error (error);
msg = g_dbus_error_get_remote_error (error);
g_assert (res);
g_assert_cmpstr (msg, ==, "org.gtk.test.Error.Failed");
res = g_dbus_error_strip_remote_error (error);
g_assert (res);
g_assert_cmpstr (error->message, ==, "Failed");
g_clear_error (&error);
g_free (msg);
g_dbus_error_set_dbus_error (&error, "org.gtk.test.Error.Failed", "Failed again", "Prefix %d", 1);
res = g_dbus_error_is_remote_error (error);
msg = g_dbus_error_get_remote_error (error);
g_assert (res);
g_assert_cmpstr (msg, ==, "org.gtk.test.Error.Failed");
res = g_dbus_error_strip_remote_error (error);
g_assert (res);
g_assert_cmpstr (error->message, ==, "Prefix 1: Failed again");
g_clear_error (&error);
g_free (msg);
error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_NOT_EMPTY, "Not Empty");
res = g_dbus_error_is_remote_error (error);
msg = g_dbus_error_get_remote_error (error);
g_assert (!res);
g_assert_cmpstr (msg, ==, NULL);
res = g_dbus_error_strip_remote_error (error);
g_assert (!res);
g_assert_cmpstr (error->message, ==, "Not Empty");
g_clear_error (&error);
error = g_error_new_literal (test_error_quark, TEST_ERROR_BLA, "Bla");
msg = g_dbus_error_encode_gerror (error);
g_assert_cmpstr (msg, ==, "org.gtk.test.Error.Bla");
g_free (msg);
g_clear_error (&error);
res = g_dbus_error_unregister_error (test_error_quark,
TEST_ERROR_BLA, "org.gtk.test.Error.Bla");
g_assert (res);
}
/* ---------------------------------------------------------------------------------------------------- */
@ -193,6 +263,7 @@ main (int argc,
g_test_add_func ("/gdbus/registered-errors", test_registered_errors);
g_test_add_func ("/gdbus/unregistered-errors", test_unregistered_errors);
g_test_add_func ("/gdbus/transparent-gerror", test_transparent_gerror);
g_test_add_func ("/gdbus/register-error", test_register_error);
return g_test_run();
}