[telepathy-gabble/master] Port test-content-adding-removal to jingletest2

Will Thompson will.thompson at collabora.co.uk
Sat Apr 18 05:32:07 PDT 2009


---
 .../twisted/jingle/test-content-adding-removal.py  |  149 +++++++-------------
 1 files changed, 54 insertions(+), 95 deletions(-)

diff --git a/tests/twisted/jingle/test-content-adding-removal.py b/tests/twisted/jingle/test-content-adding-removal.py
index ff4cfb2..b85c469 100644
--- a/tests/twisted/jingle/test-content-adding-removal.py
+++ b/tests/twisted/jingle/test-content-adding-removal.py
@@ -5,51 +5,27 @@ the first one and lastly remove the second stream, which
 closes the session.
 """
 
-from gabbletest import exec_test, make_result_iq, sync_stream
-from servicetest import make_channel_proxy, tp_path_prefix
-import jingletest
+from gabbletest import make_result_iq
+from servicetest import (
+    wrap_channel, make_channel_proxy, tp_path_prefix, assertEquals,
+    EventPattern,
+    )
+from jingletest2 import (
+    JingleTest2, test_dialects, JingleProtocol031, JingleProtocol015,
+    )
 import constants as cs
 
-from twisted.words.xish import domish, xpath
+def test(jp, q, bus, conn, stream):
+    jt = JingleTest2(jp, conn, q, stream, 'test at localhost', 'foo at bar.com/Foo')
+    jt.prepare()
 
-def test(q, bus, conn, stream):
-    jt = jingletest.JingleTest(stream, 'test at localhost', 'foo at bar.com/Foo')
-
-    # Connecting
-    conn.Connect()
-
-    q.expect('dbus-signal', signal='StatusChanged', args=[1, 1])
-
-    q.expect('stream-authenticated')
-    q.expect('dbus-signal', signal='PresenceUpdate',
-        args=[{1L: (0L, {u'available': {}})}])
-    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
-
-    self_handle = conn.GetSelfHandle()
-
-    # We need remote end's presence for capabilities
-    jt.send_remote_presence()
-
-    # Gabble doesn't trust it, so makes a disco
-    event = q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info',
-             to='foo at bar.com/Foo')
-
-    jt.send_remote_disco_reply(event.stanza)
-
-    # Force Gabble to process the caps before calling RequestChannel
-    sync_stream(q, stream)
-
-    handle = conn.RequestHandles(cs.HT_CONTACT, [jt.remote_jid])[0]
+    handle = conn.RequestHandles(cs.HT_CONTACT, [jt.peer])[0]
     path = conn.RequestChannel(
         cs.CHANNEL_TYPE_STREAMED_MEDIA, cs.HT_CONTACT, handle, True)
 
-    signalling_iface = make_channel_proxy(conn, path, 'Channel.Interface.MediaSignalling')
-    media_iface = make_channel_proxy(conn, path, 'Channel.Type.StreamedMedia')
-    group_iface = make_channel_proxy(conn, path, 'Channel.Interface.Group')
-
-    # This is the interesting part of this test
+    chan = wrap_channel(bus.get_object(conn.bus_name, path), 'StreamedMedia')
 
-    media_iface.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_AUDIO])
+    chan.StreamedMedia.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_AUDIO])
 
     # S-E gets notified about new session handler, and calls Ready on it
     e = q.expect('dbus-signal', signal='NewSessionHandler')
@@ -67,44 +43,45 @@ def test(q, bus, conn, stream):
 
     # Before sending the initiate, request another stream
 
-    media_iface.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_VIDEO])
+    chan.StreamedMedia.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_VIDEO])
 
     e = q.expect('dbus-signal', signal='NewStreamHandler')
     stream_id2 = e.args[1]
 
     stream_handler2 = make_channel_proxy(conn, e.args[0], 'Media.StreamHandler')
 
-    # We set both streams as ready, which will trigger the session invite
+    # We set both streams as ready, which will trigger the session initiate
     stream_handler.Ready(jt.get_audio_codecs_dbus())
     stream_handler.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
     stream_handler2.Ready(jt.get_audio_codecs_dbus())
     stream_handler2.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
 
     # We changed our mind locally, don't want video
-    media_iface.RemoveStreams([stream_id2])
+    chan.StreamedMedia.RemoveStreams([stream_id2])
 
-    e = q.expect('stream-iq')
-    assert e.query.name == 'jingle'
-    assert e.query['action'] == 'session-initiate'
+    e = q.expect('stream-iq', iq_type='set', predicate=lambda x:
+        jp.match_jingle_action(x.query, 'session-initiate'))
     stream.send(make_result_iq(stream, e.stanza))
 
-    e2 = q.expect('stream-iq', predicate=lambda x:
-        xpath.queryForNodes("/iq/jingle[@action='content-remove']",
-            x.stanza))
+    jt.set_sid_from_initiate(e.query)
 
-    jt.outgoing_call_reply(e.query['sid'], True, with_video=True)
-    q.expect('stream-iq', iq_type='result')
+    # Gabble sends content-remove for the video stream...
+    e2 = q.expect('stream-iq', iq_type='set', predicate=lambda x:
+        jp.match_jingle_action(x.query, 'content-remove'))
+
+    # ...but before the peer notices, they accept the call.
+    jt.accept(with_video=True)
 
     # Only now the remote end removes the video stream; if gabble mistakenly
     # marked it as accepted on session acceptance, it'll crash right about
     # now. If it's good, stream will be really removed, and
     # we can proceed.
-
     stream.send(make_result_iq(stream, e2.stanza))
 
     q.expect('dbus-signal', signal='StreamRemoved')
 
-    media_iface.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_VIDEO])
+    # Actually, we *do* want video!
+    chan.StreamedMedia.RequestStreams(handle, [cs.MEDIA_STREAM_TYPE_VIDEO])
 
     e = q.expect('dbus-signal', signal='NewStreamHandler')
     stream2_id = e.args[1]
@@ -115,66 +92,48 @@ def test(q, bus, conn, stream):
     stream_handler2.Ready(jt.get_audio_codecs_dbus())
     stream_handler2.StreamState(cs.MEDIA_STREAM_STATE_CONNECTED)
 
-    e = q.expect('stream-iq')
-    assert e.query.name == 'jingle'
-    assert e.query['action'] == 'content-add'
-    c = e.query.firstChildElement ()
-    assert c['creator'] == 'initiator', c['creator'] + " should be initiator"
+    e = q.expect('stream-iq', iq_type='set', predicate=lambda x:
+        jp.match_jingle_action(x.query, 'content-add'))
+    c = e.query.firstChildElement()
+    assertEquals('initiator', c['creator'])
     stream.send(make_result_iq(stream, e.stanza))
 
-    iq, jingle = jt._jingle_stanza('content-accept')
-
-    content = domish.Element((None, 'content'))
-    content['creator'] = 'initiator'
-    content['name'] = 'stream2'
-    content['senders'] = 'both'
-    jingle.addChild(content)
-
-    desc = domish.Element(("http://jabber.org/protocol/jingle/description/audio", 'description'))
-    for codec, id, rate in jt.audio_codecs:
-        p = domish.Element((None, 'payload-type'))
-        p['name'] = codec
-        p['id'] = str(id)
-        p['rate'] = str(rate)
-        desc.addChild(p)
-
-    content.addChild(desc)
+    # Peer accepts
+    jt.content_accept(e.query, 'video')
 
-    xport = domish.Element(("http://www.google.com/transport/p2p", 'transport'))
-    content.addChild(xport)
-
-    stream.send(iq.toXml())
-
-    e = q.expect('dbus-signal', signal='SetStreamPlaying', args=[1])
+    # Let's start sending and receiving video!
+    q.expect_many(
+        EventPattern('dbus-signal', signal='SetStreamPlaying', args=[True]),
+        EventPattern('dbus-signal', signal='SetStreamSending', args=[True]),
+        )
 
+    # Now, the call draws to a close.
     # We first remove the original stream
-    media_iface.RemoveStreams([stream_id])
+    chan.StreamedMedia.RemoveStreams([stream_id])
 
-    e = q.expect('stream-iq', iq_type='set')
-    assert e.query.name == 'jingle'
-    assert e.query['action'] == 'content-remove'
+    e = q.expect('stream-iq', iq_type='set', predicate=lambda x:
+        jp.match_jingle_action(x.query, 'content-remove'))
     stream.send(make_result_iq(stream, e.stanza))
 
     # Then we remove the second stream, which terminates the session
-    media_iface.RemoveStreams([stream2_id])
+    chan.StreamedMedia.RemoveStreams([stream2_id])
 
-    e = q.expect('stream-iq')
-    assert e.query.name == 'jingle'
-    assert e.query['action'] == 'session-terminate'
-    stream.send(make_result_iq(stream, e.stanza))
+    st, closed = q.expect_many(
+        EventPattern('stream-iq', iq_type='set', predicate=lambda x:
+            jp.match_jingle_action(x.query, 'session-terminate')),
+        # Gabble shouldn't wait for the peer to ack the terminate before
+        # considering the call finished.
+        EventPattern('dbus-signal', signal='Closed',
+            path=path[len(tp_path_prefix):]),
+        )
 
-    # Now the session should be terminated
-
-    e = q.expect('dbus-signal', signal='Closed')
-    assert (tp_path_prefix + e.path) == path
+    stream.send(make_result_iq(stream, st.stanza))
 
     # Test completed, close the connection
     conn.Disconnect()
     q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
 
-    return True
-
 
 if __name__ == '__main__':
-    exec_test(test)
+    test_dialects(test, [JingleProtocol015, JingleProtocol031])
 
-- 
1.5.6.5




More information about the telepathy-commits mailing list