[Telepathy-commits] [telepathy-glib/master] Add a regression test for GetStatuses and the Statuses property

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Jan 29 05:12:05 PST 2009


---
 .gitignore                 |    1 +
 tests/dbus/Makefile.am     |    3 +
 tests/dbus/self-presence.c |  232 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 236 insertions(+), 0 deletions(-)
 create mode 100644 tests/dbus/self-presence.c

diff --git a/.gitignore b/.gitignore
index b009e25..54aeb88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -86,6 +86,7 @@ tests/dbus/test-invalidated-while-invoking-signals
 tests/dbus/test-message-mixin
 tests/dbus/test-properties
 tests/dbus/test-message-mixin
+tests/dbus/test-self-presence
 tests/dbus/test-text-mixin
 tests/dbus/test-text-respawn
 tests/dbus/test-unsupported-interface
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index 7206b1d..7a1c22c 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -20,6 +20,7 @@ noinst_PROGRAMS = \
     test-invalidated-while-invoking-signals \
     test-message-mixin \
     test-properties \
+    test-self-presence \
     test-text-mixin \
     test-text-respawn \
     test-unsupported-interface
@@ -74,6 +75,8 @@ nodist_test_properties_SOURCES = \
     _gen/svc.h \
     _gen/svc.c
 
+test_self_presence_SOURCES = self-presence.c
+
 test_text_mixin_LDADD = \
     $(LDADD) \
     $(top_builddir)/examples/cm/echo/libexample-cm-echo.la
diff --git a/tests/dbus/self-presence.c b/tests/dbus/self-presence.c
new file mode 100644
index 0000000..09565a3
--- /dev/null
+++ b/tests/dbus/self-presence.c
@@ -0,0 +1,232 @@
+/* Feature test for setting your own presence.
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * Copying and distribution of this file, with or without modification,
+ * are permitted in any medium without royalty provided the copyright
+ * notice and this notice are preserved.
+ */
+
+#include <telepathy-glib/connection.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/debug.h>
+#include <telepathy-glib/gtypes.h>
+#include <telepathy-glib/interfaces.h>
+
+#include "tests/lib/contacts-conn.h"
+#include "tests/lib/debug.h"
+#include "tests/lib/myassert.h"
+#include "tests/lib/util.h"
+
+static int fail = 0;
+
+static void
+myassert_failed (void)
+{
+  fail = 1;
+}
+
+static void
+test_simple_presence (ContactsConnection *service_conn,
+                      TpConnection *client_conn)
+{
+  GError *error = NULL;
+  GValue *value = NULL;
+  GHashTable *statuses;
+  GValueArray *spec;
+
+  MYASSERT (tp_cli_dbus_properties_run_get (client_conn, -1,
+        TP_IFACE_CONNECTION_INTERFACE_SIMPLE_PRESENCE, "Statuses",
+        &value, &error, NULL), "");
+  MYASSERT_NO_ERROR (error);
+
+  MYASSERT (G_VALUE_TYPE (value) == TP_HASH_TYPE_SIMPLE_STATUS_SPEC_MAP,
+      ": %s != %s", G_VALUE_TYPE_NAME (value),
+      g_type_name (TP_HASH_TYPE_SIMPLE_STATUS_SPEC_MAP));
+
+  statuses = g_value_get_boxed (value);
+
+  spec = g_hash_table_lookup (statuses, "available");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
+  MYASSERT (g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* can have message */
+
+  spec = g_hash_table_lookup (statuses, "busy");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_BUSY);
+  MYASSERT (g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* can have message */
+
+  spec = g_hash_table_lookup (statuses, "away");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_AWAY);
+  MYASSERT (g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* can have message */
+
+  spec = g_hash_table_lookup (statuses, "offline");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
+  MYASSERT (!g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+
+  spec = g_hash_table_lookup (statuses, "unknown");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_UNKNOWN);
+  MYASSERT (!g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+
+  spec = g_hash_table_lookup (statuses, "error");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_ERROR);
+  MYASSERT (!g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+
+  g_value_unset (value);
+  g_free (value);
+}
+
+static void
+test_complex_presence (ContactsConnection *service_conn,
+              TpConnection *client_conn)
+{
+  GHashTable *statuses = NULL;
+  GValueArray *spec;
+  GHashTable *params;
+  GError *error = NULL;
+
+  MYASSERT (tp_cli_connection_interface_presence_run_get_statuses (
+        client_conn, -1, &statuses, &error, NULL), "");
+  MYASSERT_NO_ERROR (error);
+
+  spec = g_hash_table_lookup (statuses, "available");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_AVAILABLE);
+  MYASSERT (g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* exclusive */
+  params = g_value_get_boxed (spec->values + 3);
+  MYASSERT (params != NULL, "");
+  MYASSERT_SAME_UINT (g_hash_table_size (params), 1);
+  MYASSERT_SAME_STRING (
+      (const gchar *) g_hash_table_lookup (params, "message"), "s");
+
+  spec = g_hash_table_lookup (statuses, "away");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_AWAY);
+  MYASSERT (g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* exclusive */
+  params = g_value_get_boxed (spec->values + 3);
+  MYASSERT (params != NULL, "");
+  MYASSERT_SAME_UINT (g_hash_table_size (params), 1);
+  MYASSERT_SAME_STRING (
+      (const gchar *) g_hash_table_lookup (params, "message"), "s");
+
+  spec = g_hash_table_lookup (statuses, "busy");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_BUSY);
+  MYASSERT (g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* exclusive */
+  params = g_value_get_boxed (spec->values + 3);
+  MYASSERT (params != NULL, "");
+  MYASSERT_SAME_UINT (g_hash_table_size (params), 1);
+  MYASSERT_SAME_STRING (
+      (const gchar *) g_hash_table_lookup (params, "message"), "s");
+
+  spec = g_hash_table_lookup (statuses, "offline");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_OFFLINE);
+  MYASSERT (!g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* exclusive */
+  params = g_value_get_boxed (spec->values + 3);
+  MYASSERT (params != NULL, "");
+  MYASSERT_SAME_UINT (g_hash_table_size (params), 0);
+
+  spec = g_hash_table_lookup (statuses, "error");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_ERROR);
+  MYASSERT (!g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* exclusive */
+  params = g_value_get_boxed (spec->values + 3);
+  MYASSERT (params != NULL, "");
+  MYASSERT_SAME_UINT (g_hash_table_size (params), 0);
+
+  spec = g_hash_table_lookup (statuses, "unknown");
+  MYASSERT (spec != NULL, "");
+  MYASSERT_SAME_UINT (g_value_get_uint (spec->values + 0),
+      TP_CONNECTION_PRESENCE_TYPE_UNKNOWN);
+  MYASSERT (!g_value_get_boolean (spec->values + 1), ""); /* can set on self */
+  MYASSERT (g_value_get_boolean (spec->values + 2), ""); /* exclusive */
+  params = g_value_get_boxed (spec->values + 3);
+  MYASSERT (params != NULL, "");
+  MYASSERT_SAME_UINT (g_hash_table_size (params), 0);
+
+}
+
+int
+main (int argc,
+      char **argv)
+{
+  TpDBusDaemon *dbus;
+  ContactsConnection *service_conn;
+  TpBaseConnection *service_conn_as_base;
+  gchar *name;
+  gchar *conn_path;
+  GError *error = NULL;
+  TpConnection *client_conn;
+
+  /* Setup */
+
+  g_type_init ();
+  tp_debug_set_flags ("all");
+  dbus = tp_dbus_daemon_new (tp_get_bus ());
+
+  service_conn = CONTACTS_CONNECTION (g_object_new (
+        CONTACTS_TYPE_CONNECTION,
+        "account", "me at example.com",
+        "protocol", "simple",
+        NULL));
+  service_conn_as_base = TP_BASE_CONNECTION (service_conn);
+  MYASSERT (service_conn != NULL, "");
+  MYASSERT (service_conn_as_base != NULL, "");
+
+  MYASSERT (tp_base_connection_register (service_conn_as_base, "simple",
+        &name, &conn_path, &error), "");
+  MYASSERT_NO_ERROR (error);
+
+  client_conn = tp_connection_new (dbus, name, conn_path, &error);
+  MYASSERT (client_conn != NULL, "");
+  MYASSERT_NO_ERROR (error);
+  MYASSERT (tp_connection_run_until_ready (client_conn, TRUE, &error, NULL),
+      "");
+  MYASSERT_NO_ERROR (error);
+
+  /* Tests */
+
+  test_simple_presence (service_conn, client_conn);
+  test_complex_presence (service_conn, client_conn);
+
+  /* Teardown */
+
+  MYASSERT (tp_cli_connection_run_disconnect (client_conn, -1, &error, NULL),
+      "");
+  MYASSERT_NO_ERROR (error);
+  g_object_unref (client_conn);
+
+  service_conn_as_base = NULL;
+  g_object_unref (service_conn);
+  g_free (name);
+  g_free (conn_path);
+
+  g_object_unref (dbus);
+
+  return fail;
+}
-- 
1.5.6.5




More information about the telepathy-commits mailing list