[Telepathy-commits] [telepathy-glib/master] Add a feature test for emitting ConnectionError

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Jan 28 03:30:15 PST 2009


---
 .gitignore                    |    1 +
 tests/dbus/Makefile.am        |    3 +
 tests/dbus/connection-error.c |  115 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+), 0 deletions(-)
 create mode 100644 tests/dbus/connection-error.c

diff --git a/.gitignore b/.gitignore
index 3f9c24e..b009e25 100644
--- a/.gitignore
+++ b/.gitignore
@@ -70,6 +70,7 @@ tests/dbus/test-cli-group
 tests/dbus/test-connection
 tests/dbus/test-connection-bug-18845
 tests/dbus/test-connection-getinterfaces-failure
+tests/dbus/test-connection-error
 tests/dbus/test-connection-handles
 tests/dbus/test-connection-inject-bug16307
 tests/dbus/test-contacts
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index a7a3c35..7206b1d 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -4,6 +4,7 @@ noinst_PROGRAMS = \
     test-cli-group \
     test-connection \
     test-connection-bug-18845 \
+    test-connection-error \
     test-connection-handles \
     test-connection-inject-bug16307 \
     test-connection-getinterfaces-failure \
@@ -39,6 +40,8 @@ test_connection_bug_18845_SOURCES = connection-bug-18845.c
 
 test_connection_handles_SOURCES = connection-handles.c
 
+test_connection_error_SOURCES = connection-error.c
+
 test_connection_inject_bug16307_SOURCES = connection-inject-bug16307.c
 
 test_connection_getinterfaces_failure_SOURCES = \
diff --git a/tests/dbus/connection-error.c b/tests/dbus/connection-error.c
new file mode 100644
index 0000000..243a579
--- /dev/null
+++ b/tests/dbus/connection-error.c
@@ -0,0 +1,115 @@
+/* Feature test for ConnectionError signal emission
+ *
+ * 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/interfaces.h>
+#include <telepathy-glib/proxy-subclass.h>
+
+#include "tests/lib/myassert.h"
+#include "tests/lib/simple-conn.h"
+
+static int fail = 0;
+
+static void
+myassert_failed (void)
+{
+  fail = 1;
+}
+
+static int connection_errors;
+
+static void
+on_connection_error (TpConnection *conn,
+                     const gchar *error,
+                     GHashTable *details,
+                     gpointer user_data,
+                     GObject *weak_object)
+{
+  connection_errors++;
+  MYASSERT_SAME_STRING (error, "com.example.DomainSpecificError");
+  MYASSERT_SAME_UINT (g_hash_table_size (details), 0);
+}
+
+static void
+on_status_changed (TpConnection *conn,
+                   guint status,
+                   guint reason,
+                   gpointer user_data,
+                   GObject *weak_object)
+{
+  MYASSERT_SAME_UINT (status, TP_CONNECTION_STATUS_DISCONNECTED);
+  MYASSERT_SAME_UINT (reason, TP_CONNECTION_STATUS_REASON_NETWORK_ERROR);
+  g_main_loop_quit (user_data);
+}
+
+int
+main (int argc,
+      char **argv)
+{
+  TpDBusDaemon *dbus;
+  SimpleConnection *service_conn;
+  TpBaseConnection *service_conn_as_base;
+  gchar *name;
+  gchar *conn_path;
+  GError *error = NULL;
+  TpConnection *conn;
+  GMainLoop *mainloop;
+
+  g_type_init ();
+  tp_debug_set_flags ("all");
+  mainloop = g_main_loop_new (NULL, FALSE);
+  dbus = tp_dbus_daemon_new (tp_get_bus ());
+
+  service_conn = SIMPLE_CONNECTION (g_object_new (
+        SIMPLE_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);
+
+  conn = tp_connection_new (dbus, name, conn_path, &error);
+  MYASSERT (conn != NULL, "");
+  MYASSERT_NO_ERROR (error);
+  MYASSERT (tp_connection_run_until_ready (conn, TRUE, &error, NULL),
+      "");
+  MYASSERT_NO_ERROR (error);
+
+  connection_errors = 0;
+  tp_cli_connection_connect_to_connection_error (conn, on_connection_error,
+      NULL, NULL, NULL, NULL);
+  tp_cli_connection_connect_to_status_changed (conn, on_status_changed,
+      mainloop, NULL, NULL, NULL);
+
+  tp_base_connection_disconnect_with_dbus_error (service_conn_as_base,
+      "com.example.DomainSpecificError", NULL,
+      TP_CONNECTION_STATUS_REASON_NETWORK_ERROR);
+
+  g_main_loop_run (mainloop);
+
+  MYASSERT_SAME_UINT (connection_errors, 1);
+
+  service_conn_as_base = NULL;
+  g_object_unref (service_conn);
+  g_free (name);
+  g_free (conn_path);
+
+  g_object_unref (dbus);
+  g_main_loop_unref (mainloop);
+
+  return fail;
+}
-- 
1.5.6.5




More information about the telepathy-commits mailing list