[Telepathy-commits] [telepathy-glib/master] Add setup code for a TpConnectionManager regression test

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Feb 12 03:22:58 PST 2009


---
 .gitignore             |    1 +
 tests/dbus/Makefile.am |    6 +++
 tests/dbus/cm.c        |  117 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 124 insertions(+), 0 deletions(-)
 create mode 100644 tests/dbus/cm.c

diff --git a/.gitignore b/.gitignore
index 577b35f..b874bc8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,6 +67,7 @@ tags
 tests/dbus/test-call-cancellation
 tests/dbus/test-channel-introspect
 tests/dbus/test-cli-group
+tests/dbus/test-cm
 tests/dbus/test-connection
 tests/dbus/test-connection-bug-18845
 tests/dbus/test-connection-getinterfaces-failure
diff --git a/tests/dbus/Makefile.am b/tests/dbus/Makefile.am
index bac66e0..1d8f9f3 100644
--- a/tests/dbus/Makefile.am
+++ b/tests/dbus/Makefile.am
@@ -2,6 +2,7 @@ noinst_PROGRAMS = \
     test-call-cancellation \
     test-channel-introspect \
     test-cli-group \
+    test-cm \
     test-connection \
     test-connection-bug-18845 \
     test-connection-error \
@@ -37,6 +38,11 @@ test_channel_introspect_SOURCES = channel-introspect.c
 
 test_cli_group_SOURCES = cli-group.c
 
+test_cm_SOURCES = cm.c
+test_cm_LDADD = \
+    $(LDADD) \
+    $(top_builddir)/examples/cm/echo/libexample-cm-echo.la
+
 test_connection_SOURCES = connection.c
 
 test_connection_bug_18845_SOURCES = connection-bug-18845.c
diff --git a/tests/dbus/cm.c b/tests/dbus/cm.c
new file mode 100644
index 0000000..19ae25d
--- /dev/null
+++ b/tests/dbus/cm.c
@@ -0,0 +1,117 @@
+/* Feature test for https://bugs.freedesktop.org/show_bug.cgi?id=18291
+ *
+ * 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-manager.h>
+#include <telepathy-glib/debug.h>
+
+#include "examples/cm/echo/connection-manager.h"
+
+typedef struct {
+    GMainLoop *mainloop;
+    TpDBusDaemon *dbus;
+    ExampleEchoConnectionManager *service_cm;
+
+    TpConnectionManager *cm;
+} Test;
+
+static void
+setup (Test *test,
+       gconstpointer data)
+{
+  TpBaseConnectionManager *service_cm_as_base;
+  gboolean ok;
+
+  g_type_init ();
+  tp_debug_set_flags ("all");
+
+  test->mainloop = g_main_loop_new (NULL, FALSE);
+  test->dbus = tp_dbus_daemon_dup (NULL);
+  g_assert (test->dbus != NULL);
+
+  test->service_cm = EXAMPLE_ECHO_CONNECTION_MANAGER (g_object_new (
+        EXAMPLE_TYPE_ECHO_CONNECTION_MANAGER,
+        NULL));
+  g_assert (test->service_cm != NULL);
+  service_cm_as_base = TP_BASE_CONNECTION_MANAGER (test->service_cm);
+  g_assert (service_cm_as_base != NULL);
+
+  ok = tp_base_connection_manager_register (service_cm_as_base);
+  g_assert (ok);
+
+  test->cm = NULL;
+}
+
+static void
+teardown (Test *test,
+          gconstpointer data)
+{
+  g_object_unref (test->service_cm);
+  test->service_cm = NULL;
+  g_object_unref (test->dbus);
+  test->dbus = NULL;
+  g_main_loop_unref (test->mainloop);
+  test->mainloop = NULL;
+}
+
+static void
+test_valid_name (void)
+{
+  GError *error = NULL;
+
+  g_assert (tp_connection_manager_check_valid_name ("gabble", NULL));
+
+  g_assert (tp_connection_manager_check_valid_name ("l33t_cm", NULL));
+
+  g_assert (!tp_connection_manager_check_valid_name ("wtf tbh", &error));
+  g_assert (error != NULL);
+  g_clear_error (&error);
+
+  g_assert (!tp_connection_manager_check_valid_name ("0pointer", &error));
+  g_assert (error != NULL);
+  g_clear_error (&error);
+}
+
+static void
+test_file (Test *test,
+           gconstpointer data)
+{
+  GError *error = NULL;
+
+  test->cm = tp_connection_manager_new (test->dbus, "test_manager_file",
+      NULL, &error);
+  g_assert (error == NULL);
+  g_test_queue_unref (test->cm);
+}
+
+static void
+test_dbus (Test *test,
+           gconstpointer data)
+{
+  GError *error = NULL;
+
+  test->cm = tp_connection_manager_new (test->dbus,
+      TP_BASE_CONNECTION_MANAGER_GET_CLASS (test->service_cm)->cm_dbus_name,
+      NULL, &error);
+  g_assert (error == NULL);
+  g_test_queue_unref (test->cm);
+}
+
+int
+main (int argc,
+      char **argv)
+{
+  g_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/cm/valid-name", test_valid_name);
+  g_test_add ("/cm/file", Test, NULL, setup, test_file, teardown);
+  g_test_add ("/cm/dbus", Test, NULL, setup, test_dbus, teardown);
+
+  return g_test_run ();
+}
-- 
1.5.6.5




More information about the telepathy-commits mailing list