From 94008714587761b1972c5a018b06762fd5b92d63 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 11 Sep 2013 13:40:56 +0100 Subject: [PATCH 1/3] 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. --- 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 -- 1.8.4.rc3