[Telepathy-commits] [telepathy-glib/master] Test some more complex .manager file parsing

Simon McVittie simon.mcvittie at collabora.co.uk
Thu Feb 12 05:16:30 PST 2009


---
 tests/dbus/cm.c |  221 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 200 insertions(+), 21 deletions(-)

diff --git a/tests/dbus/cm.c b/tests/dbus/cm.c
index e4cdbdf..b0216c1 100644
--- a/tests/dbus/cm.c
+++ b/tests/dbus/cm.c
@@ -134,6 +134,28 @@ on_got_info_expect_file (TpConnectionManager *self,
   g_assert_cmpuint (info_source, ==, test->cm->info_source);
 
   g_main_loop_quit (test->mainloop);
+}
+
+static void
+test_file_got_info (Test *test,
+                    gconstpointer data)
+{
+  GError *error = NULL;
+  gulong id;
+  const TpConnectionManagerParam *param;
+  const TpConnectionManagerProtocol *protocol;
+
+  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);
 
   g_assert_cmpstr (test->cm->name, ==, "spurious");
   g_assert_cmpuint (test->cm->running, ==, FALSE);
@@ -146,40 +168,57 @@ on_got_info_expect_file (TpConnectionManager *self,
   /* 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, ==,
+  protocol = test->cm->protocols[0];
+  g_assert_cmpstr (protocol->name, ==, "normal");
+
+  param = &protocol->params[0];
+  g_assert_cmpstr (param->name, ==, "account");
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+  g_assert_cmpuint (param->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, ==,
+
+  param = &protocol->params[1];
+  g_assert_cmpstr (param->name, ==, "password");
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+  g_assert_cmpuint (param->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, ==,
+  param = &protocol->params[2];
+  g_assert_cmpstr (param->name, ==, "register");
+  g_assert_cmpstr (param->dbus_signature, ==, "b");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+
+  param = &protocol->params[3];
+  g_assert (param->name == NULL);
+
+  protocol = test->cm->protocols[1];
+  g_assert_cmpstr (protocol->name, ==, "weird");
+
+  param = &protocol->params[0];
+  g_assert_cmpstr (param->name, ==, "com.example.Bork.Bork.Bork");
+  g_assert_cmpuint (param->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);
+  g_assert_cmpstr (param->dbus_signature, ==, "u");
+
+  param = &protocol->params[1];
+  g_assert (param->name == NULL);
+
+  protocol = test->cm->protocols[2];
+  g_assert (protocol == NULL);
 }
 
 static void
-test_file_got_info (Test *test,
-                    gconstpointer data)
+test_complex_file_got_info (Test *test,
+                            gconstpointer data)
 {
   GError *error = NULL;
   gulong id;
+  const TpConnectionManagerParam *param;
+  const TpConnectionManagerProtocol *protocol;
 
-  test->cm = tp_connection_manager_new (test->dbus, "spurious",
+  test->cm = tp_connection_manager_new (test->dbus, "test_manager_file",
       NULL, &error);
   g_assert (TP_IS_CONNECTION_MANAGER (test->cm));
   g_assert (error == NULL);
@@ -190,6 +229,144 @@ test_file_got_info (Test *test,
       G_CALLBACK (on_got_info_expect_file), test);
   g_main_loop_run (test->mainloop);
   g_signal_handler_disconnect (test->cm, id);
+
+  g_assert_cmpstr (test->cm->name, ==, "test_manager_file");
+  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);
+  g_assert (test->cm->protocols[3] == NULL);
+
+  /* FIXME: it's not technically an API guarantee that protocols and params
+   * come out in this order... */
+
+  protocol = test->cm->protocols[0];
+
+  g_assert_cmpstr (protocol->name, ==, "foo");
+
+  param = &protocol->params[0];
+  g_assert_cmpstr (param->name, ==, "account");
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+
+  param = &protocol->params[1];
+  g_assert_cmpstr (param->name, ==, "password");
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_SECRET);
+
+  param = &protocol->params[2];
+  g_assert_cmpstr (param->name, ==, "encryption-key");
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_SECRET);
+
+  param = &protocol->params[3];
+  g_assert_cmpstr (param->name, ==, "port");
+  g_assert_cmpstr (param->dbus_signature, ==, "q");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+
+  param = &protocol->params[4];
+  g_assert_cmpstr (param->name, ==, "register");
+  g_assert_cmpstr (param->dbus_signature, ==, "b");
+  g_assert_cmpuint (param->flags, ==, 0);
+
+  param = &protocol->params[5];
+  g_assert_cmpstr (param->name, ==, "server-list");
+  g_assert_cmpstr (param->dbus_signature, ==, "as");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+
+  param = &protocol->params[6];
+  g_assert (param->name == NULL);
+
+  protocol = test->cm->protocols[1];
+  g_assert_cmpstr (protocol->name, ==, "bar");
+
+  param = &protocol->params[0];
+  g_assert_cmpstr (param->name, ==, "account");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+
+  param = &protocol->params[1];
+  g_assert_cmpstr (param->name, ==, "encryption-key");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_SECRET);
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+
+  param = &protocol->params[2];
+  g_assert_cmpstr (param->name, ==, "password");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_SECRET);
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+
+  param = &protocol->params[3];
+  g_assert_cmpstr (param->name, ==, "port");
+  g_assert_cmpstr (param->dbus_signature, ==, "q");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+
+  param = &protocol->params[4];
+  g_assert_cmpstr (param->name, ==, "register");
+  g_assert_cmpstr (param->dbus_signature, ==, "b");
+  g_assert_cmpuint (param->flags, ==, 0);
+
+  param = &protocol->params[5];
+  g_assert_cmpstr (param->name, ==, "server-list");
+  g_assert_cmpstr (param->dbus_signature, ==, "as");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+
+  param = &protocol->params[6];
+  g_assert (param->name == NULL);
+
+  protocol = test->cm->protocols[2];
+  g_assert_cmpstr (test->cm->protocols[2]->name, ==, "somewhat-pathological");
+
+  param = &protocol->params[0];
+  g_assert_cmpstr (param->name, ==, "foo");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_REQUIRED | TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+
+  param = &protocol->params[1];
+  g_assert_cmpstr (param->name, ==, "semicolons");
+  g_assert_cmpuint (param->flags, ==,
+      TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT | TP_CONN_MGR_PARAM_FLAG_SECRET);
+  g_assert_cmpstr (param->dbus_signature, ==, "s");
+
+  param = &protocol->params[2];
+  g_assert_cmpstr (param->name, ==, "list");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (param->dbus_signature, ==, "as");
+
+  param = &protocol->params[3];
+  g_assert_cmpstr (param->name, ==, "unterminated-list");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (param->dbus_signature, ==, "as");
+
+  param = &protocol->params[4];
+  g_assert_cmpstr (param->name, ==, "spaces-in-list");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (param->dbus_signature, ==, "as");
+
+  param = &protocol->params[5];
+  g_assert_cmpstr (param->name, ==, "escaped-semicolon-in-list");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (param->dbus_signature, ==, "as");
+
+  param = &protocol->params[6];
+  g_assert_cmpstr (param->name, ==, "doubly-escaped-semicolon-in-list");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (param->dbus_signature, ==, "as");
+
+  param = &protocol->params[7];
+  g_assert_cmpstr (param->name, ==, "triply-escaped-semicolon-in-list");
+  g_assert_cmpuint (param->flags, ==, TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT);
+  g_assert_cmpstr (param->dbus_signature, ==, "as");
+
 }
 
 static void
@@ -238,6 +415,8 @@ main (int argc,
   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/file (complex)", Test, NULL, setup,
+      test_complex_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