telepathy-glib: tp_connection_dup_detailed_error_vardict: add and test
Simon McVittie
smcv at kemper.freedesktop.org
Mon Apr 16 12:01:27 PDT 2012
Module: telepathy-glib
Branch: master
Commit: c0a58f8c543cefb9024ab5d088aca1be7fe37389
URL: http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=c0a58f8c543cefb9024ab5d088aca1be7fe37389
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Thu Apr 12 18:24:27 2012 +0100
tp_connection_dup_detailed_error_vardict: add and test
Reviewed-by: Jonny Lamb <jonny.lamb at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=30422
---
docs/reference/telepathy-glib-sections.txt | 1 +
telepathy-glib/connection.c | 33 ++++++++++++++++++++++++++++
telepathy-glib/connection.h | 3 ++
tests/dbus/connection-error.c | 19 ++++++++++++++++
4 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index fb8b47c..09950bf 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -4192,6 +4192,7 @@ tp_connection_set_contact_info_finish
TP_UNKNOWN_CONNECTION_STATUS
TP_ERRORS_DISCONNECTED
tp_connection_get_detailed_error
+tp_connection_dup_detailed_error_vardict
tp_connection_add_client_interest
tp_connection_add_client_interest_by_id
tp_connection_bind_connection_status_to_property
diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c
index 8acd374..6eb42a0 100644
--- a/telepathy-glib/connection.c
+++ b/telepathy-glib/connection.c
@@ -3302,6 +3302,39 @@ tp_connection_get_detailed_error (TpConnection *self,
}
/**
+ * tp_connection_dup_detailed_error_vardict:
+ * @self: a connection
+ * @details: (out) (allow-none) (transfer full):
+ * optionally used to return a %G_VARIANT_TYPE_VARDICT with details
+ * of the error
+ *
+ * If the connection has disconnected, return the D-Bus error name with which
+ * it disconnected (in particular, this is %TP_ERROR_STR_CANCELLED if it was
+ * disconnected by a user request).
+ *
+ * Otherwise, return %NULL, without altering @details.
+ *
+ * Returns: (transfer full) (allow-none): a D-Bus error name, or %NULL.
+ *
+ * Since: 0.19.UNRELEASED
+ */
+gchar *
+tp_connection_dup_detailed_error_vardict (TpConnection *self,
+ GVariant **details)
+{
+ const GHashTable *asv;
+ const gchar *error = tp_connection_get_detailed_error (self, &asv);
+
+ if (error == NULL)
+ return NULL;
+
+ if (details != NULL)
+ *details = _tp_asv_to_vardict (asv);
+
+ return g_strdup (error);
+}
+
+/**
* tp_connection_add_client_interest:
* @self: a connection
* @interested_in: a string identifying an interface or part of an interface
diff --git a/telepathy-glib/connection.h b/telepathy-glib/connection.h
index faf2ede..68ceff6 100644
--- a/telepathy-glib/connection.h
+++ b/telepathy-glib/connection.h
@@ -188,6 +188,9 @@ gboolean tp_connection_parse_object_path (TpConnection *self, gchar **protocol,
const gchar *tp_connection_get_detailed_error (TpConnection *self,
const GHashTable **details);
+gchar *tp_connection_dup_detailed_error_vardict (TpConnection *self,
+ GVariant **details) G_GNUC_WARN_UNUSED_RESULT;
+
void tp_connection_add_client_interest (TpConnection *self,
const gchar *interested_in);
diff --git a/tests/dbus/connection-error.c b/tests/dbus/connection-error.c
index 4e27b39..c602183 100644
--- a/tests/dbus/connection-error.c
+++ b/tests/dbus/connection-error.c
@@ -291,6 +291,10 @@ test_detailed_error (Test *test,
{
GError *error = NULL;
const GHashTable *asv;
+ gchar *str;
+ GVariant *variant;
+ gboolean ok;
+ gint32 bees;
asv = GUINT_TO_POINTER (0xDEADBEEF);
g_assert_cmpstr (tp_connection_get_detailed_error (test->conn, NULL), ==,
@@ -353,6 +357,21 @@ test_detailed_error (Test *test,
"not enough bees");
g_assert_cmpint (tp_asv_get_int32 (asv, "bees-required", NULL), ==, 2342);
+ str = tp_connection_dup_detailed_error_vardict (test->conn, NULL);
+ g_assert_cmpstr (str, ==, "com.example.DomainSpecificError");
+ g_free (str);
+ str = tp_connection_dup_detailed_error_vardict (test->conn, &variant);
+ g_assert_cmpstr (str, ==, "com.example.DomainSpecificError");
+ g_free (str);
+ g_assert (variant != NULL);
+ ok = g_variant_lookup (variant, "debug-message", "s", &str);
+ g_assert (ok);
+ g_assert_cmpstr (str, ==, "not enough bees");
+ g_free (str);
+ ok = g_variant_lookup (variant, "bees-required", "i", &bees);
+ g_assert (ok);
+ g_assert_cmpint (bees, ==, 2342);
+
g_assert_cmpstr (g_quark_to_string (error->domain), ==,
g_quark_to_string (example_com_error_quark ()));
g_assert_cmpuint (error->code, ==, DOMAIN_SPECIFIC_ERROR);
More information about the telepathy-commits
mailing list