[Telepathy-commits] [telepathy-glib/master] TpConnectionManager: extend test coverage

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


Currently, there's a race in which connection managers without
a .manager file won't necessarily ever emit got-info (#18207).
However, calling tp_connection_manager_activate() can act as a
workaround for this.

The got-info-based API is rubbish anyway... in a later patch I'll
introduce something usable.
---
 tests/dbus/cm.c |  141 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 134 insertions(+), 7 deletions(-)

diff --git a/tests/dbus/cm.c b/tests/dbus/cm.c
index 19ae25d..e4cdbdf 100644
--- a/tests/dbus/cm.c
+++ b/tests/dbus/cm.c
@@ -79,28 +79,152 @@ test_valid_name (void)
 }
 
 static void
-test_file (Test *test,
-           gconstpointer data)
+on_got_info_expect_none (TpConnectionManager *self,
+                         guint info_source,
+                         gpointer p)
+{
+  Test *test = p;
+
+  g_assert (self == test->cm);
+  g_assert_cmpuint (info_source, ==, TP_CM_INFO_SOURCE_NONE);
+  g_assert_cmpuint (info_source, ==, test->cm->info_source);
+
+  g_main_loop_quit (test->mainloop);
+}
+
+static void
+test_nothing_got_info (Test *test,
+                       gconstpointer data)
+{
+  GError *error = NULL;
+  gulong id;
+
+  test->cm = tp_connection_manager_new (test->dbus, "not_actually_there",
+      NULL, &error);
+  g_assert (TP_IS_CONNECTION_MANAGER (test->cm));
+  g_assert (error == NULL);
+  g_test_queue_unref (test->cm);
+
+  /* Spin the mainloop until we get the got-info signal. This API is rubbish.
+   * In particular, got-info isn't guaranteed to be emitted at all,
+   * unless you call tp_connection_manager_activate (#18207). As a
+   * workaround for that, you can call tp_connection_manager_activate. */
+  g_test_bug ("18207");
+  tp_connection_manager_activate (test->cm);
+  id = g_signal_connect (test->cm, "got-info",
+      G_CALLBACK (on_got_info_expect_none), test);
+  g_main_loop_run (test->mainloop);
+  g_signal_handler_disconnect (test->cm, id);
+
+  g_assert_cmpstr (test->cm->name, ==, "not_actually_there");
+  g_assert_cmpuint (test->cm->running, ==, FALSE);
+  g_assert_cmpuint (test->cm->info_source, ==, TP_CM_INFO_SOURCE_NONE);
+  g_assert (test->cm->protocols == NULL);
+}
+
+static void
+on_got_info_expect_file (TpConnectionManager *self,
+                         guint info_source,
+                         gpointer p)
+{
+  Test *test = p;
+
+  g_assert (self == test->cm);
+  g_assert_cmpuint (info_source, ==, TP_CM_INFO_SOURCE_FILE);
+  g_assert_cmpuint (info_source, ==, test->cm->info_source);
+
+  g_main_loop_quit (test->mainloop);
+
+  g_assert_cmpstr (test->cm->name, ==, "spurious");
+  g_assert_cmpuint (test->cm->running, ==, FALSE);
+  g_assert_cmpuint (test->cm->info_source, ==, TP_CM_INFO_SOURCE_FILE);
+  g_assert (test->cm->protocols != NULL);
+  g_assert (test->cm->protocols[0] != NULL);
+  g_assert (test->cm->protocols[1] != NULL);
+  g_assert (test->cm->protocols[2] == NULL);
+
+  /* FIXME: it's not technically an API guarantee that protocols and params
+   * come out in this order... */
+
+  g_assert_cmpstr (test->cm->protocols[0]->name, ==, "normal");
+  g_assert_cmpstr (test->cm->protocols[0]->params[0].name, ==, "account");
+  g_assert_cmpstr (test->cm->protocols[0]->params[0].dbus_signature, ==, "s");
+  g_assert_cmpuint (test->cm->protocols[0]->params[0].flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER);
+  g_assert_cmpstr (test->cm->protocols[0]->params[1].name, ==, "password");
+  g_assert_cmpstr (test->cm->protocols[0]->params[1].dbus_signature, ==, "s");
+  g_assert_cmpuint (test->cm->protocols[0]->params[1].flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_REGISTER |
+      TP_CONN_MGR_PARAM_FLAG_SECRET);
+  g_assert_cmpstr (test->cm->protocols[0]->params[2].name, ==, "register");
+  g_assert_cmpstr (test->cm->protocols[0]->params[2].dbus_signature, ==, "b");
+  g_assert_cmpuint (test->cm->protocols[0]->params[2].flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert (test->cm->protocols[0]->params[3].name == NULL);
+
+  g_assert_cmpstr (test->cm->protocols[1]->name, ==, "weird");
+  g_assert_cmpstr (test->cm->protocols[1]->params[0].name, ==,
+      "com.example.Bork.Bork.Bork");
+  g_assert_cmpuint (test->cm->protocols[1]->params[0].flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_DBUS_PROPERTY |
+      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (test->cm->protocols[1]->params[0].dbus_signature, ==, "u");
+  g_assert (test->cm->protocols[1]->params[1].name == NULL);
+}
+
+static void
+test_file_got_info (Test *test,
+                    gconstpointer data)
 {
   GError *error = NULL;
+  gulong id;
 
-  test->cm = tp_connection_manager_new (test->dbus, "test_manager_file",
+  test->cm = tp_connection_manager_new (test->dbus, "spurious",
       NULL, &error);
+  g_assert (TP_IS_CONNECTION_MANAGER (test->cm));
   g_assert (error == NULL);
   g_test_queue_unref (test->cm);
+
+  g_test_bug ("18207");
+  id = g_signal_connect (test->cm, "got-info",
+      G_CALLBACK (on_got_info_expect_file), test);
+  g_main_loop_run (test->mainloop);
+  g_signal_handler_disconnect (test->cm, id);
 }
 
 static void
-test_dbus (Test *test,
-           gconstpointer data)
+on_got_info_expect_live (TpConnectionManager *self,
+                         guint info_source,
+                         gpointer p)
+{
+  Test *test = p;
+
+  g_assert (self == test->cm);
+  g_assert_cmpuint (info_source, ==, TP_CM_INFO_SOURCE_LIVE);
+  g_assert_cmpuint (info_source, ==, test->cm->info_source);
+
+  g_main_loop_quit (test->mainloop);
+}
+
+static void
+test_dbus_got_info (Test *test,
+                    gconstpointer data)
 {
   GError *error = NULL;
+  gulong id;
 
   test->cm = tp_connection_manager_new (test->dbus,
       TP_BASE_CONNECTION_MANAGER_GET_CLASS (test->service_cm)->cm_dbus_name,
       NULL, &error);
+  g_assert (TP_IS_CONNECTION_MANAGER (test->cm));
   g_assert (error == NULL);
   g_test_queue_unref (test->cm);
+
+  g_test_bug ("18207");
+  id = g_signal_connect (test->cm, "got-info",
+      G_CALLBACK (on_got_info_expect_live), test);
+  g_main_loop_run (test->mainloop);
+  g_signal_handler_disconnect (test->cm, id);
 }
 
 int
@@ -108,10 +232,13 @@ main (int argc,
       char **argv)
 {
   g_test_init (&argc, &argv, NULL);
+  g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id=");
 
   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);
+  g_test_add ("/cm/nothing", Test, NULL, setup, test_nothing_got_info,
+      teardown);
+  g_test_add ("/cm/file", Test, NULL, setup, test_file_got_info, teardown);
+  g_test_add ("/cm/dbus", Test, NULL, setup, test_dbus_got_info, teardown);
 
   return g_test_run ();
 }
-- 
1.5.6.5




More information about the telepathy-commits mailing list