[Telepathy-commits] [telepathy-glib/master] tests/dbus/connection-error.c: exercise custom error remapping and the client side of ConnectionError

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Jan 28 04:42:24 PST 2009


---
 tests/dbus/connection-error.c |   58 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/tests/dbus/connection-error.c b/tests/dbus/connection-error.c
index 243a579..83f2e63 100644
--- a/tests/dbus/connection-error.c
+++ b/tests/dbus/connection-error.c
@@ -51,6 +51,54 @@ on_status_changed (TpConnection *conn,
   g_main_loop_quit (user_data);
 }
 
+typedef enum
+{
+  DOMAIN_SPECIFIC_ERROR = 0,
+} ExampleError;
+
+static GType
+example_com_error_get_type (void)
+{
+  static gsize type = 0;
+
+  if (g_once_init_enter (&type))
+    {
+      static const GEnumValue values[] = {
+            { DOMAIN_SPECIFIC_ERROR, "DOMAIN_SPECIFIC_ERROR",
+              "DomainSpecificError" },
+            { 0 }
+      };
+      GType gtype;
+
+      g_assert (sizeof (GType) <= sizeof (gsize));
+
+      gtype = g_enum_register_static ("ExampleError", values);
+      g_once_init_leave (&type, gtype);
+    }
+
+  return (GType) type;
+}
+
+static GQuark
+example_com_error_quark (void)
+{
+  static gsize quark = 0;
+
+  if (g_once_init_enter (&quark))
+    {
+      GQuark domain = g_quark_from_static_string ("com.example");
+
+      g_assert (sizeof (GQuark) <= sizeof (gsize));
+
+      g_type_init ();
+      dbus_g_error_domain_register (domain, "com.example",
+          example_com_error_get_type ());
+      g_once_init_leave (&quark, domain);
+    }
+
+  return (GQuark) quark;
+}
+
 int
 main (int argc,
       char **argv)
@@ -69,6 +117,9 @@ main (int argc,
   mainloop = g_main_loop_new (NULL, FALSE);
   dbus = tp_dbus_daemon_new (tp_get_bus ());
 
+  tp_proxy_subclass_add_error_mapping (TP_TYPE_CONNECTION,
+      "com.example", example_com_error_quark (), example_com_error_get_type ());
+
   service_conn = SIMPLE_CONNECTION (g_object_new (
         SIMPLE_TYPE_CONNECTION,
         "account", "me at example.com",
@@ -103,6 +154,13 @@ main (int argc,
 
   MYASSERT_SAME_UINT (connection_errors, 1);
 
+  MYASSERT (!tp_connection_run_until_ready (conn, FALSE, &error, NULL), "");
+  MYASSERT_SAME_STRING (g_quark_to_string (error->domain),
+      g_quark_to_string (example_com_error_quark ()));
+  MYASSERT_SAME_UINT (error->code, DOMAIN_SPECIFIC_ERROR);
+  g_error_free (error);
+  error = NULL;
+
   service_conn_as_base = NULL;
   g_object_unref (service_conn);
   g_free (name);
-- 
1.5.6.5




More information about the telepathy-commits mailing list