summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2011-09-23 15:10:21 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2011-09-23 15:10:21 +0100
commita9f652cfa4485e5ba350ad9d6d78cd50ef521758 (patch)
tree28f477712879542ecfe033ad5d1e45ec12a07821
parenta4da8ebb4d7fd9bb448d0c044713a4c32b644897 (diff)
tests: add more gabble based tests
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--.gitignore3
-rw-r--r--telepathy-ytstenut-glib/tests/Makefile.am5
-rw-r--r--telepathy-ytstenut-glib/tests/server-client-ping.c6
-rw-r--r--telepathy-ytstenut-glib/tests/server-client-pong.c6
-rw-r--r--telepathy-ytstenut-glib/tests/server-nosey-status.c318
-rw-r--r--telepathy-ytstenut-glib/tests/server-passing-service.c124
-rw-r--r--telepathy-ytstenut-glib/tests/server-passing-status.c203
7 files changed, 654 insertions, 11 deletions
diff --git a/.gitignore b/.gitignore
index 18a752b..b839f5f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -52,6 +52,9 @@ tp-glib-tools/telepathy-glib-env
/telepathy-ytstenut-glib/tests/passing-status
/telepathy-ytstenut-glib/tests/server-client-ping
/telepathy-ytstenut-glib/tests/server-client-pong
+/telepathy-ytstenut-glib/tests/server-nosey-status
+/telepathy-ytstenut-glib/tests/server-passing-service
+/telepathy-ytstenut-glib/tests/server-passing-status
/docs/reference/xml
/docs/reference/html
diff --git a/telepathy-ytstenut-glib/tests/Makefile.am b/telepathy-ytstenut-glib/tests/Makefile.am
index c2c505c..71b7260 100644
--- a/telepathy-ytstenut-glib/tests/Makefile.am
+++ b/telepathy-ytstenut-glib/tests/Makefile.am
@@ -22,4 +22,7 @@ noinst_PROGRAMS = \
passing-service \
passing-status \
server-client-pong \
- server-client-ping
+ server-client-ping \
+ server-nosey-status \
+ server-passing-service \
+ server-passing-status
diff --git a/telepathy-ytstenut-glib/tests/server-client-ping.c b/telepathy-ytstenut-glib/tests/server-client-ping.c
index d404c44..8b60b2e 100644
--- a/telepathy-ytstenut-glib/tests/server-client-ping.c
+++ b/telepathy-ytstenut-glib/tests/server-client-ping.c
@@ -283,12 +283,11 @@ int
main (int argc,
char **argv)
{
- TpDBusDaemon *dbus;
TpYtsAccountManager *am;
TpAccount *account;
gchar *path;
- if (argv[1] == NULL || argv[2] == NULL || argv[3] == NULL || argv[4] == NULL
+ if (argc < 5
|| !tp_dbus_check_valid_interface_name (argv[3], NULL)
|| !tp_dbus_check_valid_interface_name (argv[4], NULL))
{
@@ -302,8 +301,6 @@ main (int argc,
local_service = argv[3];
remote_service = argv[4];
- dbus = tp_dbus_daemon_dup (NULL);
-
am = tp_yts_account_manager_dup ();
path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE, argv[1]);
@@ -319,7 +316,6 @@ main (int argc,
g_object_unref (account);
g_object_unref (am);
- g_object_unref (dbus);
return 0;
}
diff --git a/telepathy-ytstenut-glib/tests/server-client-pong.c b/telepathy-ytstenut-glib/tests/server-client-pong.c
index 6def2ae..9abe780 100644
--- a/telepathy-ytstenut-glib/tests/server-client-pong.c
+++ b/telepathy-ytstenut-glib/tests/server-client-pong.c
@@ -126,12 +126,11 @@ int
main (int argc,
char **argv)
{
- TpDBusDaemon *dbus;
TpYtsAccountManager *am;
TpAccount *account;
gchar *path;
- if (argv[1] == NULL || argv[2] == NULL
+ if (argc < 3
|| !tp_dbus_check_valid_interface_name (argv[2], NULL))
{
g_print ("usage: %s [account] [service name]\n", argv[0]);
@@ -140,8 +139,6 @@ main (int argc,
g_type_init ();
- dbus = tp_dbus_daemon_dup (NULL);
-
am = tp_yts_account_manager_dup ();
path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE, argv[1]);
@@ -157,7 +154,6 @@ main (int argc,
g_object_unref (account);
g_object_unref (am);
- g_object_unref (dbus);
return 0;
}
diff --git a/telepathy-ytstenut-glib/tests/server-nosey-status.c b/telepathy-ytstenut-glib/tests/server-nosey-status.c
new file mode 100644
index 0000000..978bbe8
--- /dev/null
+++ b/telepathy-ytstenut-glib/tests/server-nosey-status.c
@@ -0,0 +1,318 @@
+/*
+ * server-nosey-status.c - a little demo to print out status/service changes
+ *
+ * Copyright (C) 2011 Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include <signal.h>
+
+#include <telepathy-glib/util.h>
+
+#include <telepathy-ytstenut-glib/telepathy-ytstenut-glib.h>
+
+static GMainLoop *loop = NULL;
+static TpYtsAccountManager *am = NULL;
+static TpYtsClient *client = NULL;
+
+static void
+getoutofhere (void)
+{
+ tp_clear_object (&client);
+ /* we called Hold in main, so let's let that go here by calling
+ * Release */
+ g_main_loop_quit (loop);
+}
+
+static void
+status_changed_cb (TpYtsStatus *proxy,
+ const gchar *contact_id,
+ const gchar *capability,
+ const gchar *service_name,
+ const gchar *status,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ g_print ("StatusChanged:\n");
+ g_print (" - contact ID: %s\n", contact_id);
+ g_print (" - capability: %s\n", capability);
+ g_print (" - service name: %s\n", service_name);
+ g_print (" - status: %s\n", status);
+}
+
+static void
+service_added_cb (TpYtsStatus *proxy,
+ const gchar *contact_id,
+ const gchar *service_name,
+ const GValueArray *service,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ const gchar *type;
+ GHashTable *names;
+ gchar **caps;
+
+ GHashTableIter iter;
+ gpointer key, value;
+
+ tp_value_array_unpack ((GValueArray *) service, 3,
+ &type, &names, &caps);
+
+ g_print ("ServiceAdded:\n");
+ g_print (" - contact ID: %s\n", contact_id);
+ g_print (" - service name: %s\n", service_name);
+
+ g_hash_table_iter_init (&iter, names);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ g_print (" - name: %s: %s\n", (const gchar *) key, (const gchar *) value);
+ }
+
+ while (caps != NULL && *caps != NULL)
+ {
+ g_print (" - capability: %s\n", *caps);
+ caps++;
+ }
+}
+
+static void
+service_removed_cb (TpYtsStatus *proxy,
+ const gchar *contact_id,
+ const gchar *service_name,
+ gpointer user_data,
+ GObject *weak_object)
+{
+ g_print ("ServiceRemoved:\n");
+ g_print (" - contact ID: %s\n", contact_id);
+ g_print (" - service name: %s\n", service_name);
+}
+
+static void
+service_foreach (gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ const gchar *service_name = key;
+ GValueArray *array = value;
+
+ GHashTableIter iter;
+ gpointer one, two;
+
+ const gchar *service_type;
+ GHashTable *names;
+ const gchar * const *capabilities;
+
+ tp_value_array_unpack (array, 3,
+ &service_type,
+ &names,
+ &capabilities);
+
+ g_print (" - service: %s\n", service_name);
+ g_print (" - type: %s\n", service_type);
+
+ g_hash_table_iter_init (&iter, names);
+ while (g_hash_table_iter_next (&iter, &one, &two))
+ {
+ g_print (" - name: %s: %s\n",
+ (const gchar *) one, (const gchar *) two);
+ }
+
+ for (; capabilities != NULL && *capabilities != NULL; capabilities++)
+ {
+ g_print (" - capability: %s\n", *capabilities);
+ }
+}
+
+static void
+status_foreach (gpointer key,
+ gpointer value,
+ gpointer data)
+{
+ const gchar *capability = key;
+ GHashTable *info = value;
+
+ GHashTableIter iter;
+ gpointer one, two;
+
+ g_print (" - capability: %s\n", capability);
+
+ g_hash_table_iter_init (&iter, info);
+ while (g_hash_table_iter_next (&iter, &one, &two))
+ {
+ g_print (" - service: %s\n", (const gchar *) one);
+ g_print (" - %s\n", (const gchar *) two);
+ }
+}
+
+static void
+status_ensured_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpYtsStatus *status;
+ GError *error = NULL;
+
+ status = tp_yts_status_ensure_finish (
+ TP_ACCOUNT (source_object), result, &error);
+
+ if (status == NULL)
+ {
+ g_printerr ("Failed to ensure status: %s\n", error->message);
+ getoutofhere ();
+ }
+ else
+ {
+ GHashTable *hash;
+ GHashTableIter iter;
+ gpointer key, value;
+
+ g_print ("Got status sidecar.\n");
+
+ hash = tp_yts_status_get_discovered_services (status);
+ if (g_hash_table_size (hash) > 0)
+ {
+ g_print ("Already discovered services:\n");
+
+ g_hash_table_iter_init (&iter,
+ tp_yts_status_get_discovered_services (status));
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ const gchar *contact_id = key;
+ GHashTable *map = value;
+
+ g_print (" - %s:\n", contact_id);
+
+ g_hash_table_foreach (map, service_foreach, NULL);
+ }
+ }
+
+ hash = tp_yts_status_get_discovered_statuses (status);
+ if (g_hash_table_size (hash) > 0)
+ {
+ g_print ("Already discovered statuses:\n");
+
+ g_hash_table_iter_init (&iter, hash);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ const gchar *contact_id = key;
+ GHashTable *map = value;
+
+ g_print (" - %s:\n", contact_id);
+
+ g_hash_table_foreach (map, status_foreach, NULL);
+ }
+ }
+
+ tp_yts_status_connect_to_status_changed (status, status_changed_cb,
+ NULL, NULL, NULL, NULL);
+ tp_yts_status_connect_to_service_added (status, service_added_cb,
+ NULL, NULL, NULL, NULL);
+ tp_yts_status_connect_to_service_removed (status, service_removed_cb,
+ NULL, NULL, NULL, NULL);
+
+ /* or you could use the GObject signals:
+ g_signal_connect (status, "status-changed",
+ G_CALLBACK (status_changed_cb), NULL);
+ g_signal_connect (status, "service-added",
+ G_CALLBACK (service_added_cb), NULL);
+ g_signal_connect (status, "service-removed",
+ G_CALLBACK (service_removed_cb), NULL);
+ */
+ }
+
+ g_clear_error (&error);
+}
+
+static void
+got_account (TpAccount *account)
+{
+ client = tp_yts_client_new ("nosey.status", account);
+
+ tp_yts_client_add_interests (client,
+ "urn:ytstenut:capabilities:yts-caps-cats",
+ NULL);
+
+ tp_yts_client_register (client, NULL);
+
+ tp_yts_status_ensure_async (account,
+ NULL, status_ensured_cb, NULL);
+
+ g_object_unref (account);
+}
+
+static void
+account_prepared_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpAccount *account = TP_ACCOUNT (source_object);
+ GError *error = NULL;
+
+ if (!tp_account_prepare_finish (account, result, &error))
+ {
+ g_print ("failed to prepare account: %s\n", error->message);
+ g_clear_error (&error);
+ getoutofhere ();
+ return;
+ }
+
+ got_account (account);
+}
+
+static void
+sigint_handler (int s)
+{
+ g_print ("Cleaning up...\n");
+ getoutofhere ();
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ TpAccount *account;
+ gchar *path;
+
+ if (argc < 2)
+ {
+ g_print ("usage: %s [account name]\n", argv[0]);
+ return 1;
+ }
+
+ signal (SIGINT, sigint_handler);
+
+ g_type_init ();
+
+ am = tp_yts_account_manager_dup ();
+
+ path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE, argv[1]);
+ account = tp_yts_account_manager_ensure_account (am, path, NULL);
+ g_free (path);
+
+ tp_account_prepare_async (account, NULL, account_prepared_cb, NULL);
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+
+ g_main_loop_unref (loop);
+
+ g_object_unref (account);
+ g_object_unref (am);
+
+ return 0;
+}
diff --git a/telepathy-ytstenut-glib/tests/server-passing-service.c b/telepathy-ytstenut-glib/tests/server-passing-service.c
new file mode 100644
index 0000000..f34a04e
--- /dev/null
+++ b/telepathy-ytstenut-glib/tests/server-passing-service.c
@@ -0,0 +1,124 @@
+/*
+ * passing-service.c - demo to appear as a service and then disappear
+ *
+ * Copyright (C) 2011 Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include <telepathy-glib/util.h>
+
+#include <telepathy-ytstenut-glib/telepathy-ytstenut-glib.h>
+
+static GMainLoop *loop = NULL;
+static TpYtsAccountManager *am = NULL;
+
+static void
+getoutofhere (void)
+{
+ g_main_loop_quit (loop);
+}
+
+static gboolean
+timeout_cb (gpointer data)
+{
+ g_object_unref (data);
+ getoutofhere ();
+ return FALSE;
+}
+
+static void
+got_account (TpAccount *account,
+ gpointer user_data)
+{
+ const gchar *service = user_data;
+ TpYtsClient *client = tp_yts_client_new (service, account);
+
+ tp_yts_client_add_names (client,
+ "en_GB", "Magic Icecream Maker",
+ "en_US", "Magic Icecream Vendor",
+ "fr", "Machine à Glace Magique",
+ NULL);
+
+ tp_yts_client_add_capabilities (client,
+ "urn:ytstenut:capabilities:video",
+ "urn:ytstenut:data:jingle:rtp",
+ NULL);
+
+ tp_yts_client_add_interests (client,
+ "urn:ytstenut:capabilities:slipping-on-bananaskins",
+ NULL);
+
+ tp_yts_client_register (client, NULL);
+
+ g_timeout_add_seconds (10, timeout_cb, client);
+
+ g_object_unref (account);
+}
+
+static void
+account_prepared_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpAccount *account = TP_ACCOUNT (source_object);
+ GError *error = NULL;
+
+ if (!tp_account_prepare_finish (account, result, &error))
+ {
+ g_print ("failed to prepare account: %s\n", error->message);
+ g_clear_error (&error);
+ getoutofhere ();
+ return;
+ }
+
+ got_account (account, user_data);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ TpAccount *account;
+ gchar *path;
+
+ if (argc < 3 || !tp_dbus_check_valid_interface_name (argv[2], NULL))
+ {
+ g_print ("usage: %s [account] [service name]\n", argv[0]);
+ return 1;
+ }
+
+ g_type_init ();
+
+ am = tp_yts_account_manager_dup ();
+
+ path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE, argv[1]);
+ account = tp_yts_account_manager_ensure_account (am, path, NULL);
+ g_free (path);
+
+ tp_account_prepare_async (account, NULL, account_prepared_cb, argv[2]);
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+
+ g_main_loop_unref (loop);
+
+ g_object_unref (account);
+ g_object_unref (am);
+
+ return 0;
+}
diff --git a/telepathy-ytstenut-glib/tests/server-passing-status.c b/telepathy-ytstenut-glib/tests/server-passing-status.c
new file mode 100644
index 0000000..1ce77ad
--- /dev/null
+++ b/telepathy-ytstenut-glib/tests/server-passing-status.c
@@ -0,0 +1,203 @@
+/*
+ * passing-service.c - demo to appear as a service and then disappear
+ *
+ * Copyright (C) 2011 Intel Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#include <telepathy-glib/util.h>
+
+#include <telepathy-ytstenut-glib/telepathy-ytstenut-glib.h>
+
+static GMainLoop *loop = NULL;
+static TpYtsAccountManager *am = NULL;
+static TpYtsClient *client = NULL;
+
+static void
+getoutofhere (void)
+{
+ tp_clear_object (&client);
+ g_main_loop_quit (loop);
+}
+
+static gboolean
+leave_timeout_cb (gpointer data)
+{
+ g_print ("Let's go!\n");
+ g_object_unref (data);
+ getoutofhere ();
+ return FALSE;
+}
+
+static void
+advertise_clear_status_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpYtsStatus *status = TP_YTS_STATUS (source_object);
+ GError *error = NULL;
+
+ if (!tp_yts_status_advertise_status_finish (status, result, &error))
+ {
+ g_printerr ("Failed to advertise status: %s\n", error->message);
+ getoutofhere ();
+ }
+ else
+ {
+ g_print ("Cleared status fine...\n");
+ g_timeout_add_seconds (3, leave_timeout_cb, status);
+ }
+
+ g_clear_error (&error);
+}
+
+static gboolean
+timeout_cb (gpointer data)
+{
+ TpYtsStatus *status = data;
+
+ g_print ("Clearing status\n");
+
+ tp_yts_status_advertise_status_async (status,
+ "urn:ytstenut:capabilities:yts-caps-cats",
+ "passing.status", /* this should be the same as the client name */
+ NULL, NULL, advertise_clear_status_cb, NULL);
+ return FALSE;
+}
+
+static void
+advertise_status_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpYtsStatus *status = TP_YTS_STATUS (source_object);
+ GError *error = NULL;
+
+ if (!tp_yts_status_advertise_status_finish (status, result, &error))
+ {
+ g_printerr ("Failed to advertise status: %s\n", error->message);
+ getoutofhere ();
+ }
+ else
+ {
+ g_print ("Advertised status fine...\n");
+ g_timeout_add_seconds (3, timeout_cb, status);
+ }
+
+ g_clear_error (&error);
+}
+
+static void
+status_ensured_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpAccount *account = user_data;
+ TpYtsStatus *status;
+ GError *error = NULL;
+
+ status = tp_yts_status_ensure_finish (
+ TP_ACCOUNT (source_object), result, &error);
+
+ if (status == NULL)
+ {
+ g_printerr ("Failed to ensure status: %s\n", error->message);
+ getoutofhere ();
+ }
+ else
+ {
+ client = tp_yts_client_new ("passing.status", account);
+ tp_yts_client_register (client, NULL);
+
+ /* We need the XML here otherwise the activity attribute won't
+ * be present and it'll think we'll be trying to remove the
+ * status. */
+ tp_yts_status_advertise_status_async (status,
+ "urn:ytstenut:capabilities:yts-caps-cats",
+ "passing.status", /* this should be the same as the client name */
+ "<status xmlns='urn:ytstenut:status' from-service='service.name' "
+ "capability='urn:ytstenut:capabilities:yts-caps-cats' "
+ "activity='looking-at-cats-ooooooh'><look>at how cute they "
+ "are!</look></status>",
+ NULL, advertise_status_cb, NULL);
+ }
+
+ g_clear_error (&error);
+}
+
+static void
+got_account (TpAccount *account)
+{
+ tp_yts_status_ensure_async (account,
+ NULL, status_ensured_cb, NULL);
+
+ g_object_unref (account);
+}
+
+static void
+account_prepared_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TpAccount *account = TP_ACCOUNT (source_object);
+ GError *error = NULL;
+
+ if (!tp_account_prepare_finish (account, result, &error))
+ {
+ g_print ("failed to prepare account: %s\n", error->message);
+ g_clear_error (&error);
+ getoutofhere ();
+ return;
+ }
+
+ got_account (account);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ TpAccount *account;
+ gchar *path;
+
+ if (argc < 2)
+ {
+ g_print ("usage: %s [account]\n", argv[0]);
+ return 1;
+ }
+
+ g_type_init ();
+
+ am = tp_yts_account_manager_dup ();
+
+ path = g_strdup_printf ("%s%s", TP_ACCOUNT_OBJECT_PATH_BASE, argv[1]);
+ account = tp_yts_account_manager_ensure_account (am, path, NULL);
+ g_free (path);
+
+ tp_account_prepare_async (account, NULL, account_prepared_cb, NULL);
+
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
+
+ g_main_loop_unref (loop);
+
+ g_object_unref (account);
+ g_object_unref (am);
+
+ return 0;
+}