telepathy-gabble: GabbleFtManager: announce incoming FT channels individually
Simon McVittie
smcv at kemper.freedesktop.org
Thu Sep 12 03:33:10 PDT 2013
Module: telepathy-gabble
Branch: master
Commit: 6fcba9164c643abbdfffa42b33d2cb3fe4e3bd65
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=6fcba9164c643abbdfffa42b33d2cb3fe4e3bd65
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date: Wed Sep 11 13:40:56 2013 +0100
GabbleFtManager: announce incoming FT channels individually
tp_channel_manager_emit_new_channels() is deprecated, because
announcing bundles of related channels together seemed a nice idea, but
it turns out to be really difficult to deal with in practice.
This requires some interesting contortions in test-multift.py, which
exercised the "bundle of related channels" stuff.
Signed-off-by: Simon McVittie <simon.mcvittie at collabora.co.uk>
Reviewed-by: Guillaume Desmottes <guillaume.desmottes at collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=69194
---
src/ft-manager.c | 9 +---
tests/twisted/jingle-share/test-multift.py | 59 +++++++++++++++++++---------
2 files changed, 42 insertions(+), 26 deletions(-)
diff --git a/src/ft-manager.c b/src/ft-manager.c
index a4266b5..675992a 100644
--- a/src/ft-manager.c
+++ b/src/ft-manager.c
@@ -289,8 +289,6 @@ static void
gabble_ft_manager_channels_created (GabbleFtManager *self, GList *channels)
{
GList *i;
- GHashTable *new_channels = g_hash_table_new_full (g_direct_hash,
- g_direct_equal, NULL, NULL);
for (i = channels; i ; i = i->next)
{
@@ -304,12 +302,9 @@ gabble_ft_manager_channels_created (GabbleFtManager *self, GList *channels)
self->priv->channels = g_list_append (self->priv->channels, chan);
/* The channels can't satisfy a request because this will always be called
when we receive an incoming jingle-share session */
- g_hash_table_insert (new_channels, chan, NULL);
+ tp_channel_manager_emit_new_channel (self,
+ TP_EXPORTABLE_CHANNEL (chan), NULL);
}
-
- tp_channel_manager_emit_new_channels (self, new_channels);
-
- g_hash_table_unref (new_channels);
}
#endif
diff --git a/tests/twisted/jingle-share/test-multift.py b/tests/twisted/jingle-share/test-multift.py
index d318e42..41da7c6 100644
--- a/tests/twisted/jingle-share/test-multift.py
+++ b/tests/twisted/jingle-share/test-multift.py
@@ -59,17 +59,46 @@ def test(q, bus, conn, stream):
url['name'] = 'preview-path'
stream.send(iq)
- event = q.expect('dbus-signal', signal="NewChannels")
- channels = event.args[0]
- # Make sure we get the right amout of channels
- assert len(channels) == len(files)
+ patterns = []
+ found = {}
+
+ def get_predicate(name, found, i):
+ # This needs to be a function so that name, found, i
+ # are part of a closure.
+
+ # /!\ This predicate has side-effects: it writes to 'found'
+ def predicate(e):
+ path, props = e.args[0][0]
+ if props[cs.CHANNEL_TYPE] != cs.CHANNEL_TYPE_FILE_TRANSFER:
+ return False
+
+ if props[cs.FT_FILENAME] == name:
+ found[i] = (path, props)
+ return True
+ return predicate
+
+ for i, f in enumerate(files):
+ type, name, size, image = f
+ if type == "folder":
+ name = "%s.tar" % name
+
+ return False
+
+ patterns.append(EventPattern('dbus-signal',
+ signal='NewChannels',
+ predicate=get_predicate(name, found, i)))
# Make sure every file transfer has a channel associated with it
- found = [False for i in files]
file_collection = None
- for channel in channels:
- path, props = channel
+ q.expect_many(*patterns)
+ assertLength(len(files), found)
+
+ channels = []
+ for i in found:
+ assert found[i] is not None
+ path, props = found[i]
+ channels.append((path, props))
# Get the FileCollection and make sure it exists
if file_collection is None:
@@ -80,17 +109,11 @@ def test(q, bus, conn, stream):
# FileCollection must be the same for every channel
assert props[cs.FT_FILE_COLLECTION] == file_collection, props
- for i, f in enumerate(files):
- type, name, size, image = f
- if type == "folder":
- name = "%s.tar" % name
- if size is None:
- size = 0
+ type, name, size, image = files[i]
+ if size is None:
+ size = 0
- if props[cs.FT_FILENAME].encode('utf=8') == name:
- assert found[i] == False
- found[i] = True
- assert props[cs.FT_SIZE] == size, props
+ assertEquals(size, props[cs.FT_SIZE])
assert props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_FILE_TRANSFER, props
assertSameSets(
@@ -118,8 +141,6 @@ def test(q, bus, conn, stream):
assert props[cs.FT_TRANSFERRED_BYTES] == 0, props
assert props[cs.FT_INITIAL_OFFSET] == 0, props
- assert False not in found
-
event = q.expect('stream-iq', to=contact,
iq_type='set', query_name='session')
session_node = event.query
More information about the telepathy-commits
mailing list