[glib] Add some more test about gdbus_error apis
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Add some more test about gdbus_error apis
- Date: Sat, 7 Aug 2010 22:57:49 +0000 (UTC)
commit 8e236f7ec1e0f620a516255a6b8ed7ae169bc87e
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Aug 7 18:55:21 2010 -0400
Add some more test about gdbus_error apis
gio/tests/gdbus-error.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 71 insertions(+), 0 deletions(-)
---
diff --git a/gio/tests/gdbus-error.c b/gio/tests/gdbus-error.c
index 2231ca8..00dfc61 100644
--- a/gio/tests/gdbus-error.c
+++ b/gio/tests/gdbus-error.c
@@ -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();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]