[next] telepathy-glib: future-account: add unset_parameter and test it

Jonny Lamb jonny at kemper.freedesktop.org
Fri May 11 02:41:34 PDT 2012


Module: telepathy-glib
Branch: next
Commit: 7955221c201193e7e1a6e41966009121c5424b2a
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=7955221c201193e7e1a6e41966009121c5424b2a

Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date:   Thu Apr 26 17:00:33 2012 +0100

future-account: add unset_parameter and test it

Signed-off-by: Jonny Lamb <jonny.lamb at collabora.co.uk>

---

 telepathy-glib/future-account.c |   21 +++++++++++++++++++++
 telepathy-glib/future-account.h |    3 +++
 tests/dbus/future-account.c     |   35 ++++++++++++++++++++++++++++++++---
 3 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/telepathy-glib/future-account.c b/telepathy-glib/future-account.c
index 61d7130..3cb708f 100644
--- a/telepathy-glib/future-account.c
+++ b/telepathy-glib/future-account.c
@@ -573,6 +573,27 @@ tp_future_account_set_parameter (TpFutureAccount *self,
 }
 
 /**
+ * tp_future_account_unset_parameter:
+ * @self: a #TpFutureAccount
+ * @key: the parameter key
+ *
+ * Unset the account parameter @key.
+ */
+void
+tp_future_account_unset_parameter (TpFutureAccount *self,
+    const gchar *key)
+{
+  TpFutureAccountPrivate *priv;
+
+  g_return_if_fail (TP_IS_FUTURE_ACCOUNT (self));
+  g_return_if_fail (key != NULL);
+
+  priv = self->priv;
+
+  g_hash_table_remove (priv->parameters, key);
+}
+
+/**
  * tp_future_account_set_parameter_string: (skip)
  * @self: a #TpFutureAccount
  * @key: the parameter key
diff --git a/telepathy-glib/future-account.h b/telepathy-glib/future-account.h
index c3eee6f..353ca38 100644
--- a/telepathy-glib/future-account.h
+++ b/telepathy-glib/future-account.h
@@ -79,6 +79,9 @@ void tp_future_account_set_requested_presence (TpFutureAccount *self,
 void tp_future_account_set_parameter (TpFutureAccount *self,
     const gchar *key, GVariant *value);
 
+void tp_future_account_unset_parameter (TpFutureAccount *self,
+    const gchar *key);
+
 void tp_future_account_set_parameter_string (TpFutureAccount *self,
     const gchar *key, const gchar *value);
 
diff --git a/tests/dbus/future-account.c b/tests/dbus/future-account.c
index 0b6b697..21c9f56 100644
--- a/tests/dbus/future-account.c
+++ b/tests/dbus/future-account.c
@@ -133,9 +133,11 @@ test_parameters (Test *test,
 
   v_str = g_variant_new_string ("banana");
   tp_future_account_set_parameter (test->account, "cheese", v_str);
+  g_variant_unref (v_str);
 
   v_int = g_variant_new_uint32 (42);
   tp_future_account_set_parameter (test->account, "life", v_int);
+  g_variant_unref (v_int);
 
   tp_future_account_set_parameter_string (test->account,
       "great", "expectations");
@@ -150,8 +152,19 @@ test_parameters (Test *test,
   g_assert_cmpuint (tp_asv_get_uint32 (params, "life", NULL), ==, 42);
   g_assert_cmpstr (tp_asv_get_string (params, "great"), ==, "expectations");
 
-  g_variant_unref (v_str);
-  g_variant_unref (v_int);
+  g_hash_table_unref (params);
+
+  /* now let's unset one and see if it's okay */
+  tp_future_account_unset_parameter (test->account, "cheese");
+
+  g_object_get (test->account,
+      "parameters", &params,
+      NULL);
+
+  g_assert_cmpuint (g_hash_table_size (params), ==, 2);
+
+  g_assert_cmpuint (tp_asv_get_uint32 (params, "life", NULL), ==, 42);
+  g_assert_cmpstr (tp_asv_get_string (params, "great"), ==, "expectations");
 
   g_hash_table_unref (params);
 }
@@ -294,7 +307,7 @@ test_create_fail (Test *test,
 
   tp_future_account_set_display_name (test->account, "Walter White");
 
-  /* this will make CreateChannel fail */
+  /* this will make CreateAccount fail */
   tp_future_account_set_parameter_string (test->account,
       "fail", "yes");
 
@@ -308,6 +321,22 @@ test_create_fail (Test *test,
   g_assert (account == NULL);
 
   g_clear_error (&test->error);
+  test->result = NULL;
+
+  /* now let's unset the fail=yes and make sure it works */
+
+  tp_future_account_unset_parameter (test->account, "fail");
+
+  tp_future_account_create_account_async (test->account,
+      tp_tests_result_ready_cb, &test->result);
+  tp_tests_run_until_result (&test->result);
+
+  account = tp_future_account_create_account_finish (test->account,
+      test->result, &test->error);
+  g_assert_no_error (test->error);
+  g_assert (account != NULL);
+
+  g_object_unref (account);
 }
 
 int



More information about the telepathy-commits mailing list