[folks] Update tp-glib copy of unit test lib



commit 9b5b7798fee20b88cab2cf78f43b4843aa8718a2
Author: Xavier Claessens <xavier claessens collabora co uk>
Date:   Wed May 9 12:08:03 2012 +0200

    Update tp-glib copy of unit test lib

 tests/lib/telepathy/contactlist/Makefile.am        |    2 +
 .../telepathy/contactlist/contact-list-manager.c   |    9 +--
 .../telepathy/contactlist/simple-account-manager.c |    6 +-
 tests/lib/telepathy/contactlist/simple-account.c   |   55 +++++++---------
 tests/lib/telepathy/contactlist/simple-conn.c      |   68 +++++++++++++++++---
 tests/lib/telepathy/contactlist/simple-conn.h      |    5 ++
 tests/lib/telepathy/contactlist/textchan-null.c    |   16 ++--
 tests/lib/telepathy/contactlist/util.c             |   49 +++++++++++---
 tests/lib/telepathy/contactlist/util.h             |    6 ++
 9 files changed, 150 insertions(+), 66 deletions(-)
---
diff --git a/tests/lib/telepathy/contactlist/Makefile.am b/tests/lib/telepathy/contactlist/Makefile.am
index 1578f67..4d1d287 100644
--- a/tests/lib/telepathy/contactlist/Makefile.am
+++ b/tests/lib/telepathy/contactlist/Makefile.am
@@ -25,6 +25,8 @@ libtp_test_contactlist_la_SOURCES = \
         contacts-conn.c \
         contacts-conn.h \
         debug.h \
+        room-list-chan.c \
+        room-list-chan.h \
         simple-account.c \
         simple-account.h \
         simple-account-manager.c \
diff --git a/tests/lib/telepathy/contactlist/contact-list-manager.c b/tests/lib/telepathy/contactlist/contact-list-manager.c
index fbb725b..638c92b 100644
--- a/tests/lib/telepathy/contactlist/contact-list-manager.c
+++ b/tests/lib/telepathy/contactlist/contact-list-manager.c
@@ -199,7 +199,7 @@ contact_list_dup_groups (TpBaseContactList *base)
 
   if (self->priv->groups != NULL)
     {
-      TpIntSetFastIter iter;
+      TpIntsetFastIter iter;
       TpHandle group;
 
       ret = g_ptr_array_sized_new (tp_handle_set_size (self->priv->groups) + 1);
@@ -231,7 +231,7 @@ contact_list_dup_contact_groups (TpBaseContactList *base,
 
   if (d != NULL && d->groups != NULL)
     {
-      TpIntSetFastIter iter;
+      TpIntsetFastIter iter;
       TpHandle group;
 
       ret = g_ptr_array_sized_new (tp_handle_set_size (d->groups) + 1);
@@ -297,7 +297,7 @@ contact_list_set_contact_groups_async (TpBaseContactList *base,
   TpIntset *set, *added_set, *removed_set;
   GPtrArray *added_names, *removed_names;
   GPtrArray *new_groups;
-  TpIntSetFastIter iter;
+  TpIntsetFastIter iter;
   TpHandle group_handle;
   guint i;
 
@@ -531,9 +531,6 @@ status_changed_cb (TpBaseConnection *conn,
           close_all (self);
         }
       break;
-
-    default:
-      break;
     }
 }
 
diff --git a/tests/lib/telepathy/contactlist/simple-account-manager.c b/tests/lib/telepathy/contactlist/simple-account-manager.c
index ab4a795..8df364a 100644
--- a/tests/lib/telepathy/contactlist/simple-account-manager.c
+++ b/tests/lib/telepathy/contactlist/simple-account-manager.c
@@ -137,9 +137,9 @@ tp_tests_simple_account_manager_class_init (
   GParamSpec *param_spec;
 
   static TpDBusPropertiesMixinPropImpl am_props[] = {
-        { "Interfaces", (gpointer) "interfaces", NULL },
-        { "ValidAccounts", (gpointer) "valid-accounts", NULL },
-        { "InvalidAccounts", (gpointer) "invalid-accounts", NULL },
+        { "Interfaces", "interfaces", NULL },
+        { "ValidAccounts", "valid-accounts", NULL },
+        { "InvalidAccounts", "invalid-accounts", NULL },
         /*
         { "SupportedAccountProperties", "supported-account-properties", NULL },
         */
diff --git a/tests/lib/telepathy/contactlist/simple-account.c b/tests/lib/telepathy/contactlist/simple-account.c
index 8036474..f424309 100644
--- a/tests/lib/telepathy/contactlist/simple-account.c
+++ b/tests/lib/telepathy/contactlist/simple-account.c
@@ -287,50 +287,45 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass)
   GObjectClass *object_class = (GObjectClass *) klass;
   GParamSpec *param_spec;
 
-#define MIXIN_PROP(N, g) \
-        { N, (gpointer) g, NULL }
-
   static TpDBusPropertiesMixinPropImpl a_props[] = {
-        MIXIN_PROP ("Interfaces", "interfaces"),
-        MIXIN_PROP ("DisplayName", "display-name"),
-        MIXIN_PROP ("Icon", "icon"),
-        MIXIN_PROP ("Valid", "valid"),
-        MIXIN_PROP ("Enabled", "enabled"),
-        MIXIN_PROP ("Nickname", "nickname"),
-        MIXIN_PROP ("Parameters", "parameters"),
-        MIXIN_PROP ("AutomaticPresence", "automatic-presence"),
-        MIXIN_PROP ("ConnectAutomatically", "connect-automatically"),
-        MIXIN_PROP ("Connection", "connection"),
-        MIXIN_PROP ("ConnectionStatus", "connection-status"),
-        MIXIN_PROP ("ConnectionStatusReason", "connection-status-reason"),
-        MIXIN_PROP ("CurrentPresence", "current-presence"),
-        MIXIN_PROP ("RequestedPresence", "requested-presence"),
-        MIXIN_PROP ("NormalizedName", "normalized-name"),
-        MIXIN_PROP ("HasBeenOnline", "has-been-online"),
-        MIXIN_PROP ("Supersedes", "supersedes"),
+        { "Interfaces", "interfaces", NULL },
+        { "DisplayName", "display-name", NULL },
+        { "Icon", "icon", NULL },
+        { "Valid", "valid", NULL },
+        { "Enabled", "enabled", NULL },
+        { "Nickname", "nickname", NULL },
+        { "Parameters", "parameters", NULL },
+        { "AutomaticPresence", "automatic-presence", NULL },
+        { "ConnectAutomatically", "connect-automatically", NULL },
+        { "Connection", "connection", NULL },
+        { "ConnectionStatus", "connection-status", NULL },
+        { "ConnectionStatusReason", "connection-status-reason", NULL },
+        { "CurrentPresence", "current-presence", NULL },
+        { "RequestedPresence", "requested-presence", NULL },
+        { "NormalizedName", "normalized-name", NULL },
+        { "HasBeenOnline", "has-been-online", NULL },
+        { "Supersedes", "supersedes", NULL },
         { NULL }
   };
 
   static TpDBusPropertiesMixinPropImpl ais_props[] = {
-        MIXIN_PROP ("StorageProvider", "storage-provider"),
-        MIXIN_PROP ("StorageIdentifier", "storage-identifier"),
-        MIXIN_PROP ("StorageSpecificInformation", "storage-specific-information"),
-        MIXIN_PROP ("StorageRestrictions", "storage-restrictions"),
+        { "StorageProvider", "storage-provider", NULL },
+        { "StorageIdentifier", "storage-identifier", NULL },
+        { "StorageSpecificInformation", "storage-specific-information", NULL },
+        { "StorageRestrictions", "storage-restrictions", NULL },
         { NULL },
   };
 
   static TpDBusPropertiesMixinPropImpl aia_props[] = {
-        MIXIN_PROP ("URISchemes", "uri-schemes"),
+        { "URISchemes", "uri-schemes", NULL },
         { NULL },
   };
 
   static TpDBusPropertiesMixinPropImpl avatar_props[] = {
-        MIXIN_PROP ("Avatar", "avatar"),
+        { "Avatar", "avatar", NULL },
         { NULL },
   };
 
-#undef MIXIN_PROP
-
   static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
         { TP_IFACE_ACCOUNT,
           tp_dbus_properties_mixin_getter_gobject_properties,
@@ -424,14 +419,14 @@ tp_tests_simple_account_class_init (TpTestsSimpleAccountClass *klass)
 
   param_spec = g_param_spec_uint ("connection-status", "connection status",
       "ConnectionStatus property",
-      0, NUM_TP_CONNECTION_STATUSES, TP_CONNECTION_STATUS_DISCONNECTED,
+      0, TP_NUM_CONNECTION_STATUSES, TP_CONNECTION_STATUS_DISCONNECTED,
       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class, PROP_CONNECTION_STATUS,
       param_spec);
 
   param_spec = g_param_spec_uint ("connection-status-reason",
       "connection status reason", "ConnectionStatusReason property",
-      0, NUM_TP_CONNECTION_STATUS_REASONS,
+      0, TP_NUM_CONNECTION_STATUS_REASONS,
       TP_CONNECTION_STATUS_REASON_NONE_SPECIFIED,
       G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (object_class, PROP_CONNECTION_STATUS_REASON,
diff --git a/tests/lib/telepathy/contactlist/simple-conn.c b/tests/lib/telepathy/contactlist/simple-conn.c
index 8a481af..8874654 100644
--- a/tests/lib/telepathy/contactlist/simple-conn.c
+++ b/tests/lib/telepathy/contactlist/simple-conn.c
@@ -25,6 +25,7 @@
 #include <telepathy-glib/util.h>
 
 #include "textchan-null.h"
+#include "room-list-chan.h"
 #include "util.h"
 
 static void conn_iface_init (TpSvcConnectionClass *);
@@ -59,7 +60,8 @@ struct _TpTestsSimpleConnectionPrivate
   gboolean break_fastpath_props;
 
   /* TpHandle => reffed TpTestsTextChannelNull */
-  GHashTable *channels;
+  GHashTable *text_channels;
+  TpTestsRoomListChan *room_list_chan;
 
   GError *get_self_handle_error /* initially NULL */ ;
 };
@@ -70,7 +72,7 @@ tp_tests_simple_connection_init (TpTestsSimpleConnection *self)
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
       TP_TESTS_TYPE_SIMPLE_CONNECTION, TpTestsSimpleConnectionPrivate);
 
-  self->priv->channels = g_hash_table_new_full (NULL, NULL, NULL,
+  self->priv->text_channels = g_hash_table_new_full (NULL, NULL, NULL,
       (GDestroyNotify) g_object_unref);
 }
 
@@ -136,7 +138,8 @@ dispose (GObject *object)
 {
   TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (object);
 
-  g_hash_table_unref (self->priv->channels);
+  g_hash_table_unref (self->priv->text_channels);
+  g_clear_object (&self->priv->room_list_chan);
 
   G_OBJECT_CLASS (tp_tests_simple_connection_parent_class)->dispose (object);
 }
@@ -178,14 +181,14 @@ tp_tests_simple_normalize_contact (TpHandleRepoIface *repo,
 {
   if (id[0] == '\0')
     {
-      g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_HANDLE,
+      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_HANDLE,
           "ID must not be empty");
       return NULL;
     }
 
   if (strchr (id, ' ') != NULL)
     {
-      g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_HANDLE,
+      g_set_error (error, TP_ERROR, TP_ERROR_INVALID_HANDLE,
           "ID must not contain spaces");
       return NULL;
     }
@@ -195,7 +198,7 @@ tp_tests_simple_normalize_contact (TpHandleRepoIface *repo,
 
 static void
 create_handle_repos (TpBaseConnection *conn,
-                     TpHandleRepoIface *repos[NUM_TP_HANDLE_TYPES])
+                     TpHandleRepoIface *repos[TP_NUM_HANDLE_TYPES])
 {
   repos[TP_HANDLE_TYPE_CONTACT] = tp_dynamic_handle_repo_new
       (TP_HANDLE_TYPE_CONTACT, tp_tests_simple_normalize_contact, NULL);
@@ -262,7 +265,8 @@ pretend_disconnected (gpointer data)
   TpTestsSimpleConnection *self = TP_TESTS_SIMPLE_CONNECTION (data);
 
   /* We are disconnected, all our channels are invalidated */
-  g_hash_table_remove_all (self->priv->channels);
+  g_hash_table_remove_all (self->priv->text_channels);
+  g_clear_object (&self->priv->room_list_chan);
 
   tp_base_connection_finish_shutdown (TP_BASE_CONNECTION (data));
   self->priv->disconnect_source = 0;
@@ -379,7 +383,8 @@ tp_tests_simple_connection_ensure_text_chan (TpTestsSimpleConnection *self,
 
   handle = tp_handle_ensure (contact_repo, target_id, NULL, NULL);
 
-  chan = g_hash_table_lookup (self->priv->channels, GUINT_TO_POINTER (handle));
+  chan = g_hash_table_lookup (self->priv->text_channels,
+      GUINT_TO_POINTER (handle));
   if (chan != NULL)
     {
       /* Channel already exist, reuse it */
@@ -398,7 +403,7 @@ tp_tests_simple_connection_ensure_text_chan (TpTestsSimpleConnection *self,
             "handle", handle,
             NULL));
 
-      g_hash_table_insert (self->priv->channels, GUINT_TO_POINTER (handle),
+      g_hash_table_insert (self->priv->text_channels, GUINT_TO_POINTER (handle),
           chan);
     }
 
@@ -410,6 +415,51 @@ tp_tests_simple_connection_ensure_text_chan (TpTestsSimpleConnection *self,
   return chan_path;
 }
 
+static void
+room_list_chan_closed_cb (TpBaseChannel *channel,
+    TpTestsSimpleConnection *self)
+{
+  g_clear_object (&self->priv->room_list_chan);
+}
+
+gchar *
+tp_tests_simple_connection_ensure_room_list_chan (TpTestsSimpleConnection *self,
+    const gchar *server,
+    GHashTable **props)
+{
+  gchar *chan_path;
+  TpBaseConnection *base_conn = (TpBaseConnection *) self;
+
+  if (self->priv->room_list_chan != NULL)
+    {
+      /* Channel already exist, reuse it */
+      g_object_get (self->priv->room_list_chan,
+          "object-path", &chan_path, NULL);
+    }
+  else
+    {
+      chan_path = g_strdup_printf ("%s/RoomListChannel",
+          base_conn->object_path);
+
+      self->priv->room_list_chan = TP_TESTS_ROOM_LIST_CHAN (
+          tp_tests_object_new_static_class (
+            TP_TESTS_TYPE_ROOM_LIST_CHAN,
+            "connection", self,
+            "object-path", chan_path,
+            "server", server ? server : "",
+            NULL));
+
+      g_signal_connect (self->priv->room_list_chan, "closed",
+          G_CALLBACK (room_list_chan_closed_cb), self);
+    }
+
+  if (props != NULL)
+    g_object_get (self->priv->room_list_chan,
+        "channel-properties", props, NULL);
+
+  return chan_path;
+}
+
 void
 tp_tests_simple_connection_set_get_self_handle_error (
     TpTestsSimpleConnection *self,
diff --git a/tests/lib/telepathy/contactlist/simple-conn.h b/tests/lib/telepathy/contactlist/simple-conn.h
index 6322f4b..837400b 100644
--- a/tests/lib/telepathy/contactlist/simple-conn.h
+++ b/tests/lib/telepathy/contactlist/simple-conn.h
@@ -72,6 +72,11 @@ void tp_tests_simple_connection_set_get_self_handle_error (
     gint code,
     const gchar *message);
 
+gchar * tp_tests_simple_connection_ensure_room_list_chan (
+    TpTestsSimpleConnection *self,
+    const gchar *server,
+    GHashTable **props);
+
 G_END_DECLS
 
 #endif /* #ifndef __TP_TESTS_SIMPLE_CONN_H__ */
diff --git a/tests/lib/telepathy/contactlist/textchan-null.c b/tests/lib/telepathy/contactlist/textchan-null.c
index 72f9015..64b156f 100644
--- a/tests/lib/telepathy/contactlist/textchan-null.c
+++ b/tests/lib/telepathy/contactlist/textchan-null.c
@@ -347,14 +347,14 @@ tp_tests_props_text_channel_class_init (TpTestsPropsTextChannelClass *klass)
 {
   GObjectClass *object_class = (GObjectClass *) klass;
   static TpDBusPropertiesMixinPropImpl channel_props[] = {
-      { "TargetHandleType", (gpointer) "handle-type", NULL },
-      { "TargetHandle", (gpointer) "handle", NULL },
-      { "ChannelType", (gpointer) "channel-type", NULL },
-      { "Interfaces", (gpointer) "interfaces", NULL },
-      { "TargetID", (gpointer) "target-id", NULL },
-      { "Requested", (gpointer) "requested", NULL },
-      { "InitiatorHandle", (gpointer) "initiator-handle", NULL },
-      { "InitiatorID", (gpointer) "initiator-id", NULL },
+      { "TargetHandleType", "handle-type", NULL },
+      { "TargetHandle", "handle", NULL },
+      { "ChannelType", "channel-type", NULL },
+      { "Interfaces", "interfaces", NULL },
+      { "TargetID", "target-id", NULL },
+      { "Requested", "requested", NULL },
+      { "InitiatorHandle", "initiator-handle", NULL },
+      { "InitiatorID", "initiator-id", NULL },
       { NULL }
   };
   static TpDBusPropertiesMixinIfaceImpl prop_interfaces[] = {
diff --git a/tests/lib/telepathy/contactlist/util.c b/tests/lib/telepathy/contactlist/util.c
index 6713182..5cb6d23 100644
--- a/tests/lib/telepathy/contactlist/util.c
+++ b/tests/lib/telepathy/contactlist/util.c
@@ -10,7 +10,7 @@
 
 #include "config.h"
 
-#include "util.h"
+#include "tests/lib/util.h"
 
 #include <telepathy-glib/connection.h>
 
@@ -375,7 +375,6 @@ _tp_create_local_socket (TpSocketAddressType address_type,
       case TP_SOCKET_ACCESS_CONTROL_PORT:
         break;
 
-      case TP_SOCKET_ACCESS_CONTROL_NETMASK:
       default:
         g_assert_not_reached ();
     }
@@ -404,10 +403,6 @@ _tp_create_local_socket (TpSocketAddressType address_type,
           break;
         }
 
-#ifndef HAVE_GIO_UNIX
-      case TP_SOCKET_ADDRESS_TYPE_UNIX:
-#endif
-      case TP_SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX:
       default:
         g_assert_not_reached ();
     }
@@ -452,10 +447,6 @@ _tp_create_local_socket (TpSocketAddressType address_type,
             G_MAXUINT);
         break;
 
-#ifndef HAVE_GIO_UNIX
-      case TP_SOCKET_ADDRESS_TYPE_UNIX:
-#endif
-      case TP_SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX:
       default:
         g_assert_not_reached ();
     }
@@ -480,3 +471,41 @@ tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection)
   g_assert (ok);
   g_object_unref (result);
 }
+
+static void
+one_contact_cb (TpConnection *connection,
+    guint n_contacts,
+    TpContact * const *contacts,
+    const gchar * const *good_ids,
+    GHashTable *bad_ids,
+    const GError *error,
+    gpointer user_data,
+    GObject *weak_object)
+{
+  TpContact **contact_loc = user_data;
+
+  g_assert_no_error (error);
+  g_assert_cmpuint (g_hash_table_size (bad_ids), ==, 0);
+  g_assert_cmpuint (n_contacts, ==, 1);
+  g_assert_cmpstr (good_ids[0], !=, NULL);
+  g_assert (contacts[0] != NULL);
+
+  *contact_loc = g_object_ref (contacts[0]);
+}
+
+TpContact *
+tp_tests_connection_run_until_contact_by_id (TpConnection *connection,
+    const gchar *id,
+    guint n_features,
+    const TpContactFeature *features)
+{
+  TpContact *contact = NULL;
+
+  tp_connection_get_contacts_by_id (connection, 1, &id, n_features, features,
+      one_contact_cb, &contact, NULL, NULL);
+
+  while (contact == NULL)
+    g_main_context_iteration (NULL, TRUE);
+
+  return contact;
+}
diff --git a/tests/lib/telepathy/contactlist/util.h b/tests/lib/telepathy/contactlist/util.h
index d0428ac..3fccc4c 100644
--- a/tests/lib/telepathy/contactlist/util.h
+++ b/tests/lib/telepathy/contactlist/util.h
@@ -73,4 +73,10 @@ void _tp_destroy_socket_control_list (gpointer data);
 
 void tp_tests_connection_assert_disconnect_succeeds (TpConnection *connection);
 
+TpContact *tp_tests_connection_run_until_contact_by_id (
+    TpConnection *connection,
+    const gchar *id,
+    guint n_features,
+    const TpContactFeature *features);
+
 #endif /* #ifndef __TP_TESTS_LIB_UTIL_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]