telepathy-glib: future-account test: add test for _create_account_async

Jonny Lamb jonny at kemper.freedesktop.org
Thu May 10 07:41:18 PDT 2012


Module: telepathy-glib
Branch: master
Commit: 625282d3428c5f19450fc22c3e60ca881c872c27
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=625282d3428c5f19450fc22c3e60ca881c872c27

Author: Jonny Lamb <jonny.lamb at collabora.co.uk>
Date:   Thu Apr 26 15:16:57 2012 +0100

future-account test: add test for _create_account_async

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

---

 telepathy-glib/future-account.c |  114 +++++++++++++++++++++++++++++++++++++++
 telepathy-glib/future-account.h |    4 ++
 tests/dbus/future-account.c     |   79 +++++++++++++++++++++++++++
 3 files changed, 197 insertions(+), 0 deletions(-)

diff --git a/telepathy-glib/future-account.c b/telepathy-glib/future-account.c
index ed6917c..61d7130 100644
--- a/telepathy-glib/future-account.c
+++ b/telepathy-glib/future-account.c
@@ -22,6 +22,7 @@
 
 #include "telepathy-glib/future-account.h"
 
+#include <telepathy-glib/gtypes.h>
 #include <telepathy-glib/util.h>
 #include <telepathy-glib/simple-client-factory.h>
 
@@ -89,6 +90,9 @@ enum {
   PROP_PROPERTIES,
   PROP_ICON_NAME,
   PROP_NICKNAME,
+  PROP_REQUESTED_PRESENCE_TYPE,
+  PROP_REQUESTED_STATUS,
+  PROP_REQUESTED_STATUS_MESSAGE,
   N_PROPS
 };
 
@@ -152,6 +156,39 @@ tp_future_account_get_property (GObject *object,
       g_value_set_string (value,
           tp_asv_get_string (self->priv->properties, "Nickname"));
       break;
+    case PROP_REQUESTED_PRESENCE_TYPE:
+      {
+        GValueArray *arr = tp_asv_get_boxed (self->priv->properties,
+            "RequestedPresence", TP_STRUCT_TYPE_SIMPLE_PRESENCE);
+
+        if (arr != NULL)
+          g_value_set_uint (value, g_value_get_uint (arr->values));
+        else
+          g_value_set_uint (value, 0);
+      }
+      break;
+    case PROP_REQUESTED_STATUS:
+      {
+        GValueArray *arr = tp_asv_get_boxed (self->priv->properties,
+            "RequestedPresence", TP_STRUCT_TYPE_SIMPLE_PRESENCE);
+
+        if (arr != NULL)
+          g_value_set_string (value, g_value_get_string (arr->values + 1));
+        else
+          g_value_set_string (value, "");
+      }
+      break;
+    case PROP_REQUESTED_STATUS_MESSAGE:
+      {
+        GValueArray *arr = tp_asv_get_boxed (self->priv->properties,
+            "RequestedPresence", TP_STRUCT_TYPE_SIMPLE_PRESENCE);
+
+        if (arr != NULL)
+          g_value_set_string (value, g_value_get_string (arr->values + 2));
+        else
+          g_value_set_string (value, "");
+      }
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -335,6 +372,48 @@ tp_future_account_class_init (TpFutureAccountClass *klass)
           "The account's nickname",
           NULL,
           G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
+  /**
+   * TpFutureAccount:requested-presence-type:
+   *
+   * The account's requested presence type (a
+   * #TpConnectionPresenceType). To change this property use
+   * tp_future_account_set_requested_presence().
+   */
+  g_object_class_install_property (object_class, PROP_REQUESTED_PRESENCE_TYPE,
+      g_param_spec_uint ("requested-presence-type",
+          "RequestedPresence",
+          "The account's requested presence type",
+          0,
+          TP_NUM_CONNECTION_PRESENCE_TYPES,
+          TP_CONNECTION_PRESENCE_TYPE_UNSET,
+          G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
+  /**
+   * TpFutureAccount:requested-status:
+   *
+   * The requested Status string of the account. To change this
+   * property use tp_future_account_set_requested_presence().
+   */
+  g_object_class_install_property (object_class, PROP_REQUESTED_STATUS,
+      g_param_spec_string ("requested-status",
+          "RequestedStatus",
+          "The account's requested status string",
+          NULL,
+          G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
+
+  /**
+   * TpFutureAccount:requested-status-message:
+   *
+   * The requested status message message of the account. To change
+   * this property use tp_future_account_set_requested_presence().
+   */
+  g_object_class_install_property (object_class, PROP_REQUESTED_STATUS_MESSAGE,
+      g_param_spec_string ("requested-status-message",
+          "RequestedStatusMessage",
+          "The requested Status message string of the account",
+          NULL,
+          G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
 }
 
 /**
@@ -429,6 +508,41 @@ tp_future_account_set_nickname (TpFutureAccount *self,
 }
 
 /**
+ * tp_future_account_set_requested_presence:
+ * @self: a #TpFutureAccount
+ * @presence: the requested presence type
+ * @status: the requested presence status
+ * @message: the requested presence message
+ *
+ * Set the requested presence for the new account, @self, to the type
+ * (@presence, @status), with message @message.
+ */
+void
+tp_future_account_set_requested_presence (TpFutureAccount *self,
+    TpConnectionPresenceType presence,
+    const gchar *status,
+    const gchar *message)
+{
+  TpFutureAccountPrivate *priv;
+  GValue *value;
+  GValueArray *arr;
+
+  g_return_if_fail (TP_IS_FUTURE_ACCOUNT (self));
+
+  priv = self->priv;
+
+  value = tp_g_value_slice_new_take_boxed (TP_STRUCT_TYPE_SIMPLE_PRESENCE,
+      dbus_g_type_specialized_construct (TP_STRUCT_TYPE_SIMPLE_PRESENCE));
+  arr = (GValueArray *) g_value_get_boxed (value);
+
+  g_value_set_uint (arr->values, presence);
+  g_value_set_string (arr->values + 1, status);
+  g_value_set_string (arr->values + 2, message);
+
+  g_hash_table_insert (priv->properties, "RequestedPresence", value);
+}
+
+/**
  * tp_future_account_set_parameter:
  * @self: a #TpFutureAccount
  * @key: the parameter key
diff --git a/telepathy-glib/future-account.h b/telepathy-glib/future-account.h
index ffd2580..c3eee6f 100644
--- a/telepathy-glib/future-account.h
+++ b/telepathy-glib/future-account.h
@@ -71,6 +71,10 @@ void tp_future_account_set_icon_name (TpFutureAccount *self,
 void tp_future_account_set_nickname (TpFutureAccount *self,
     const gchar *nickname);
 
+void tp_future_account_set_requested_presence (TpFutureAccount *self,
+    TpConnectionPresenceType presence,
+    const gchar *status, const gchar *message);
+
 /* parameters */
 void tp_future_account_set_parameter (TpFutureAccount *self,
     const gchar *key, GVariant *value);
diff --git a/tests/dbus/future-account.c b/tests/dbus/future-account.c
index c32dd78..1511764 100644
--- a/tests/dbus/future-account.c
+++ b/tests/dbus/future-account.c
@@ -162,6 +162,8 @@ test_properties (Test *test,
 {
   GHashTable *props;
   gchar *icon_name, *nickname;
+  TpConnectionPresenceType presence_type;
+  gchar *presence_status, *presence_message;
 
   test->account = tp_future_account_new (test->account_manager,
       "gabble", "jabber");
@@ -204,6 +206,81 @@ test_properties (Test *test,
 
   g_hash_table_unref (props);
   g_free (nickname);
+
+  /* next is requested presence */
+  tp_future_account_set_requested_presence (test->account,
+      TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available",
+      "come at me, bro!");
+
+  g_object_get (test->account,
+      "requested-presence-type", &presence_type,
+      "requested-status", &presence_status,
+      "requested-status-message", &presence_message,
+      NULL);
+
+  g_assert_cmpuint (presence_type, ==, TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
+  g_assert_cmpstr (presence_status, ==, "available");
+  g_assert_cmpstr (presence_message, ==, "come at me, bro!");
+
+  g_free (presence_status);
+  g_free (presence_message);
+}
+
+static void
+test_create (Test *test,
+    gconstpointer data G_GNUC_UNUSED)
+{
+  TpAccount *account;
+  GValueArray *array;
+
+  test->account = tp_future_account_new (test->account_manager,
+      "gabble", "jabber");
+
+  tp_future_account_set_display_name (test->account, "Walter White");
+  tp_future_account_set_icon_name (test->account, "gasmask");
+  tp_future_account_set_nickname (test->account, "Heisenberg");
+  tp_future_account_set_requested_presence (test->account,
+      TP_CONNECTION_PRESENCE_TYPE_AVAILABLE, "available",
+      "Better call Saul!");
+
+  tp_future_account_set_parameter_string (test->account,
+      "account", "walter at white.us");
+  tp_future_account_set_parameter_string (test->account,
+      "password", "holly");
+
+  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_assert_cmpstr (test->am->create_cm, ==, "gabble");
+  g_assert_cmpstr (test->am->create_protocol, ==, "jabber");
+  g_assert_cmpstr (test->am->create_display_name, ==, "Walter White");
+  g_assert_cmpuint (g_hash_table_size (test->am->create_parameters), ==, 2);
+  g_assert_cmpstr (tp_asv_get_string (test->am->create_parameters, "account"),
+      ==, "walter at white.us");
+  g_assert_cmpstr (tp_asv_get_string (test->am->create_parameters, "password"),
+      ==, "holly");
+  g_assert_cmpuint (g_hash_table_size (test->am->create_properties), ==, 3);
+  g_assert_cmpstr (tp_asv_get_string (test->am->create_properties, "Icon"),
+      ==, "gasmask");
+  g_assert_cmpstr (tp_asv_get_string (test->am->create_properties, "Nickname"),
+      ==, "Heisenberg");
+
+  array = tp_asv_get_boxed (test->am->create_properties, "RequestedPresence",
+      TP_STRUCT_TYPE_SIMPLE_PRESENCE);
+  g_assert_cmpuint (g_value_get_uint (array->values), ==,
+      TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
+  g_assert_cmpstr (g_value_get_string (array->values + 1), ==,
+      "available");
+  g_assert_cmpstr (g_value_get_string (array->values + 2), ==,
+      "Better call Saul!");
+
+  g_object_unref (account);
 }
 
 int
@@ -224,6 +301,8 @@ main (int argc,
       test_parameters, teardown);
   g_test_add ("/future-account/properties", Test, NULL, setup,
       test_properties, teardown);
+  g_test_add ("/future-account/create", Test, NULL, setup,
+      test_create, teardown);
 
   return g_test_run ();
 }



More information about the telepathy-commits mailing list