[telepathy-gabble/master] Test for bug 24043

David Laban david.laban at collabora.co.uk
Wed Sep 23 10:35:14 PDT 2009


Added test for http://bugs.freedesktop.org/show_bug.cgi?id=24043
and also the / 65536 bug I found.
---
 tests/twisted/jingle/jingletest2.py          |   38 ++++++++++++++++++--
 tests/twisted/jingle/test-outgoing-iceudp.py |   51 +++++++++++++++++++++++++-
 2 files changed, 84 insertions(+), 5 deletions(-)

diff --git a/tests/twisted/jingle/jingletest2.py b/tests/twisted/jingle/jingletest2.py
index 9e4341f..312d1d6 100644
--- a/tests/twisted/jingle/jingletest2.py
+++ b/tests/twisted/jingle/jingletest2.py
@@ -87,9 +87,40 @@ class JingleProtocol:
         "Creates a <transport> element for Google P2P transport"
         return ('transport', ns.GOOGLE_P2P, {}, [])
 
-    def TransportIceUdp(self):
-        "Creates a <transport> element for ICE-UDP transport"
-        return ('transport', ns.JINGLE_TRANSPORT_ICEUDP, {}, [])
+    def TransportIceUdp(self, remote_transports=[]):
+        """
+        Creates a <transport> element for ICE-UDP transport.
+        If remote_transports is present, and of the form
+        [(host, port, proto, subtype, profile, pref, transtype, user, pwd)]
+        (basically a list of Media_Stream_Handler_Transport without the
+        component number) then it will be converted to xml and added.
+        """
+        candidates = []
+        attrs = {}
+        for (host, port, proto, subtype, profile, pref, transtype, user, pwd
+                ) in remote_transports:
+            if "ufrag" not in attrs:
+                attrs = {"ufrag": user, "pwd": pwd}
+            else:
+                assert (user == attrs["ufrag"] and pwd == attrs["pwd"]
+                    ), "user and pwd should be the same across all candidates."
+
+            node = ("candidate", None, {
+                # ICE-CORE says it can be arbitrary string, even though XEP
+                # gives an int as an example.
+                "foundation": "fake",
+                "ip": host,
+                "port": str(port),
+                "protocol": ["udp", "tcp"][proto],
+                # Gabble multiplies by 65536 so we should too.
+                "priority": str(int(pref * 65536)),
+                "type":  ["host", "srflx", "srflx"][transtype],
+                "network": "0",
+                "generation": "0",# Increment this yourself if you care.
+                "component": "1", # 1 is rtp, 2 is rtcp
+                }, []) #NOTE: subtype and profile are unused
+            candidates.append(node)
+        return ('transport', ns.JINGLE_TRANSPORT_ICEUDP, attrs, candidates)
 
     def Presence(self, frm, to, caps):
         "Creates <presence> stanza with specified capabilities"
@@ -622,6 +653,7 @@ class JingleTest2:
                 in enumerate(self.remote_transports) ],
             signature='(usuussduss)')
 
+
 def test_dialects(f, dialects):
     for dialect in dialects:
         exec_test(
diff --git a/tests/twisted/jingle/test-outgoing-iceudp.py b/tests/twisted/jingle/test-outgoing-iceudp.py
index 70d9a05..209d6c5 100644
--- a/tests/twisted/jingle/test-outgoing-iceudp.py
+++ b/tests/twisted/jingle/test-outgoing-iceudp.py
@@ -76,6 +76,7 @@ def worker(jp, q, bus, conn, stream):
 
     stream.send(jp.xml(jp.ResultIq('test at localhost', e.stanza, [])))
 
+    # Make sure that it doesn't send a duplicate of our one ICE candidate here.
     ti_event = [
         EventPattern('stream-iq',
             predicate=jp.action_predicate('transport-info'))
@@ -84,16 +85,62 @@ def worker(jp, q, bus, conn, stream):
     sync_stream(q, stream)
     q.unforbid_events(ti_event)
 
+    # XEP-0166 6.4 Negotiation: "The allowable negotiations include:
+    # Exchanging particular transport candidates via the transport-info action."
+    candidate = (
+        "192.168.0.69", # host
+        668, # port
+        0, # protocol = TP_MEDIA_STREAM_BASE_PROTO_UDP
+        "RTP", # protocol subtype
+        "AVP", # profile
+        1.0, # preference
+        0, # transport type = TP_MEDIA_STREAM_TRANSPORT_TYPE_LOCAL,
+        "username",
+        "password" )
+    transport = jp.TransportIceUdp([candidate])
+
+    node = jp.SetIq(jt2.peer, jt2.jid, [
+        jp.Jingle(jt2.sid, jt2.peer, 'transport-info', [
+            jp.Content('stream1', 'initiator', 'both', [
+                transport]) ]) ])
+    stream.send(jp.xml(node))
+
+    candidate_e, result_e =  q.expect_many(
+        EventPattern('dbus-signal',  signal='AddRemoteCandidate'),
+        EventPattern('stream-iq', iq_type='result'))
+
+    fake_, (returned_candidate,) = candidate_e.args
+    assertEquals(candidate, returned_candidate[1:])
+
+    candidate = (
+        "192.168.0.69", # host
+        670, # port
+        0, # protocol = TP_MEDIA_STREAM_BASE_PROTO_UDP
+        "RTP", # protocol subtype
+        "AVP", # profile
+        1.0, # preference
+        0, # transport type = TP_MEDIA_STREAM_TRANSPORT_TYPE_LOCAL,
+        "username",
+        "password" )
+    transport = jp.TransportIceUdp([candidate])
+
+    # It is also valid to send transports in the accept.
+    # This is what pidgin does.
     node = jp.SetIq(jt2.peer, jt2.jid, [
         jp.Jingle(jt2.sid, jt2.peer, 'session-accept', [
             jp.Content('stream1', 'initiator', 'both', [
                 jp.Description('audio', [
                     jp.PayloadType(name, str(rate), str(id)) for
                         (name, id, rate) in jt2.audio_codecs ]),
-            jp.TransportIceUdp() ]) ]) ])
+                transport ]) ]) ])
     stream.send(jp.xml(node))
 
-    q.expect('stream-iq', iq_type='result')
+    candidate_e, result_e = q.expect_many(
+        EventPattern('dbus-signal',  signal='AddRemoteCandidate'),
+        EventPattern('stream-iq', iq_type='result'))
+
+    fake_, (returned_candidate,) = candidate_e.args
+    assertEquals(candidate, returned_candidate[1:])
 
     chan.Close()
     e = q.expect('stream-iq',
-- 
1.5.6.5



More information about the telepathy-commits mailing list