[Telepathy-commits] [telepathy-gabble/master] rename offer-private-dbus-tube-ibb.py to offer-private-dbus-tube.py
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Feb 27 06:08:55 PST 2009
---
tests/twisted/Makefile.am | 2 +-
tests/twisted/tubes/offer-private-dbus-tube-ibb.py | 311 --------------------
tests/twisted/tubes/offer-private-dbus-tube.py | 311 ++++++++++++++++++++
3 files changed, 312 insertions(+), 312 deletions(-)
delete mode 100644 tests/twisted/tubes/offer-private-dbus-tube-ibb.py
create mode 100644 tests/twisted/tubes/offer-private-dbus-tube.py
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index defb425..b7cba5e 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -56,7 +56,7 @@ TWISTED_TESTS = \
tubes/offer-muc-dbus-tube.py \
tubes/offer-muc-stream-tube.py \
tubes/offer-no-caps.py \
- tubes/offer-private-dbus-tube-ibb.py \
+ tubes/offer-private-dbus-tube.py \
tubes/offer-private-stream-tube.py \
tubes/request-invalid-dbus-tube.py \
tubes/ensure-si-tube.py \
diff --git a/tests/twisted/tubes/offer-private-dbus-tube-ibb.py b/tests/twisted/tubes/offer-private-dbus-tube-ibb.py
deleted file mode 100644
index b0b8e57..0000000
--- a/tests/twisted/tubes/offer-private-dbus-tube-ibb.py
+++ /dev/null
@@ -1,311 +0,0 @@
-"""Test D-Bus private tube support"""
-
-import dbus
-from dbus.connection import Connection
-from dbus.lowlevel import SignalMessage
-
-from servicetest import call_async, EventPattern, unwrap
-from gabbletest import exec_test, make_result_iq, sync_stream
-import constants as cs
-import tubetestutil as t
-
-from twisted.words.xish import domish, xpath
-import ns
-from bytestream import parse_si_offer, create_si_reply
-
-sample_parameters = dbus.Dictionary({
- 's': 'hello',
- 'ay': dbus.ByteArray('hello'),
- 'u': dbus.UInt32(123),
- 'i': dbus.Int32(-123),
- }, signature='sv')
-
-# FIXME: stolen from jingletest.py. Should be shared by all tests
-def make_presence(fromjid, tojid, caps=None):
- el = domish.Element(('jabber:client', 'presence',))
- el['from'] = fromjid
- el['to'] = tojid
-
- if caps:
- cel = domish.Element(('http://jabber.org/protocol/caps', 'c'))
- for key,value in caps.items():
- cel[key] = value
- el.addChild(cel)
-
- return el
-
-def make_caps_disco_reply(stream, req, features):
- iq = make_result_iq(stream, req)
- query = iq.firstChildElement()
-
- for f in features:
- el = domish.Element((None, 'feature'))
- el['var'] = f
- query.addChild(el)
-
- return iq
-
-def alice_accepts_tube(q, stream, iq_event, dbus_tube_id, bytestream_cls):
- iq = iq_event.stanza
-
- profile, dbus_stream_id, bytestreams = parse_si_offer(iq)
-
- assert profile == ns.TUBES
- assert bytestreams == [ns.BYTESTREAMS, ns.IBB]
-
- tube_nodes = xpath.queryForNodes('/iq/si/tube[@xmlns="%s"]'
- % ns.TUBES, iq)
- assert len(tube_nodes) == 1
- tube = tube_nodes[0]
- tube['type'] = 'dbus'
- assert tube['initiator'] == 'test at localhost'
- assert tube['service'] == 'com.example.TestCase'
- assert tube['id'] == str(dbus_tube_id)
-
- params = {}
- parameter_nodes = xpath.queryForNodes('/tube/parameters/parameter', tube)
- for node in parameter_nodes:
- assert node['name'] not in params
- params[node['name']] = (node['type'], str(node))
- assert params == {'ay': ('bytes', 'aGVsbG8='),
- 's': ('str', 'hello'),
- 'i': ('int', '-123'),
- 'u': ('uint', '123'),
- }
-
- # Alice accepts the tube
- bytestream = bytestream_cls(stream, q, dbus_stream_id, 'test at localhost/Resource',
- 'alice at localhost/Test', False)
-
- result, si = create_si_reply(stream, iq, bytestream.initiator, bytestream.get_ns())
- si.addElement((ns.TUBES, 'tube'))
- stream.send(result)
-
- bytestream.wait_bytestream_open()
-
- q.expect('dbus-signal', signal='TubeStateChanged',
- args=[dbus_tube_id, cs.TUBE_STATE_OPEN])
-
- return bytestream
-
-def send_dbus_message_to_alice(q, stream, dbus_tube_adr, bytestream):
- tube = Connection(dbus_tube_adr)
- signal = SignalMessage('/', 'foo.bar', 'baz')
- signal.append(42, signature='u')
- tube.send_message(signal)
-
- binary = bytestream.get_data()
-
- # little and big endian versions of: SIGNAL, NO_REPLY, protocol v1,
- # 4-byte payload
- assert binary.startswith('l\x04\x01\x01' '\x04\x00\x00\x00') or \
- binary.startswith('B\x04\x01\x01' '\x00\x00\x00\x04')
- # little and big endian versions of the 4-byte payload, UInt32(42)
- assert (binary[0] == 'l' and binary.endswith('\x2a\x00\x00\x00')) or \
- (binary[0] == 'B' and binary.endswith('\x00\x00\x00\x2a'))
- # XXX: verify that it's actually in the "sender" slot, rather than just
- # being in the message somewhere
-
-def offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle, bytestream_cls):
- # request tubes channel (old API)
- tubes_path = conn.RequestChannel(cs.CHANNEL_TYPE_TUBES, cs.HT_CONTACT,
- alice_handle, True)
- tubes_chan = bus.get_object(conn.bus_name, tubes_path)
- tubes_iface = dbus.Interface(tubes_chan, cs.CHANNEL_TYPE_TUBES)
- tubes_chan_iface = dbus.Interface(tubes_chan, cs.CHANNEL)
-
- # Exercise basic Channel Properties from spec 0.17.7
- channel_props = tubes_chan.GetAll(cs.CHANNEL, dbus_interface=cs.PROPERTIES_IFACE)
- assert channel_props.get('TargetHandle') == alice_handle,\
- (channel_props.get('TargetHandle'), alice_handle)
- assert channel_props.get('TargetHandleType') == cs.HT_CONTACT,\
- channel_props.get('TargetHandleType')
- assert channel_props.get('ChannelType') == cs.CHANNEL_TYPE_TUBES,\
- channel_props.get('ChannelType')
- assert 'Interfaces' in channel_props, channel_props
- assert channel_props['Interfaces'] == [], channel_props['Interfaces']
- assert channel_props['TargetID'] == 'alice at localhost', channel_props['TargetID']
- assert channel_props['Requested'] == True
- assert channel_props['InitiatorID'] == 'test at localhost'
- assert channel_props['InitiatorHandle'] == conn.GetSelfHandle()
-
- # Offer a D-Bus tube using old API
- call_async(q, tubes_iface, 'OfferDBusTube',
- 'com.example.TestCase', sample_parameters)
-
- new_tube_event, iq_event, offer_return_event = \
- q.expect_many(
- EventPattern('dbus-signal', signal='NewTube'),
- EventPattern('stream-iq', to='alice at localhost/Test'),
- EventPattern('dbus-return', method='OfferDBusTube'))
-
- # handle new_tube_event
- dbus_tube_id = new_tube_event.args[0]
- assert new_tube_event.args[1] == self_handle
- assert new_tube_event.args[2] == 0 # DBUS
- assert new_tube_event.args[3] == 'com.example.TestCase'
- assert new_tube_event.args[4] == sample_parameters
- assert new_tube_event.args[5] == cs.TUBE_STATE_REMOTE_PENDING
-
- # handle offer_return_event
- assert offer_return_event.value[0] == dbus_tube_id
-
- tubes = tubes_iface.ListTubes(byte_arrays=True)
- assert len(tubes) == 1
- expected_tube = (dbus_tube_id, self_handle, cs.TUBE_TYPE_DBUS,
- 'com.example.TestCase', sample_parameters, cs.TUBE_STATE_REMOTE_PENDING)
- t.check_tube_in_tubes(expected_tube, tubes)
-
- bytestream = alice_accepts_tube(q, stream, iq_event, dbus_tube_id, bytestream_cls)
-
- dbus_tube_adr = tubes_iface.GetDBusTubeAddress(dbus_tube_id)
- send_dbus_message_to_alice(q, stream, dbus_tube_adr, bytestream)
-
- # close the tube
- tubes_iface.CloseTube(dbus_tube_id)
- q.expect('dbus-signal', signal='TubeClosed', args=[dbus_tube_id])
-
- # and close the tubes channel
- tubes_chan_iface.Close()
- q.expect('dbus-signal', signal='Closed')
-
-
-def offer_new_dbus_tube(q, bus, conn, stream, self_handle, alice_handle, bytestream_cls):
- requestotron = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)
-
- # Offer a tube to Alice (new API)
-
- call_async(q, requestotron, 'CreateChannel',
- {cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_DBUS_TUBE,
- cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
- cs.TARGET_ID: 'alice at localhost',
- cs.DBUS_TUBE_SERVICE_NAME: 'com.example.TestCase'
- }, byte_arrays=True)
- cc_ret, nc = q.expect_many(
- EventPattern('dbus-return', method='CreateChannel'),
- EventPattern('dbus-signal', signal='NewChannels'),
- )
- tube_path, tube_props = cc_ret.value
- new_channel_details = nc.args[0]
-
- # check tube channel properties
- assert tube_props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_DBUS_TUBE
- assert tube_props[cs.INTERFACES] == [cs.CHANNEL_IFACE_TUBE]
- assert tube_props[cs.TARGET_HANDLE_TYPE] == cs.HT_CONTACT
- assert tube_props[cs.TARGET_HANDLE] == alice_handle
- assert tube_props[cs.TARGET_ID] == 'alice at localhost'
- assert tube_props[cs.REQUESTED] == True
- assert tube_props[cs.INITIATOR_HANDLE] == self_handle
- assert tube_props[cs.INITIATOR_ID] == "test at localhost"
- assert tube_props[cs.DBUS_TUBE_SERVICE_NAME] == 'com.example.TestCase'
- assert cs.DBUS_TUBE_DBUS_NAMES not in tube_props
- assert cs.TUBE_PARAMETERS not in tube_props
- assert cs.TUBE_STATE not in tube_props
-
- # Under the current implementation, creating a new-style Tube channel
- # ensures that an old-style Tubes channel exists, even though Tube channels
- # aren't visible on the Tubes channel until they're offered. Another
- # correct implementation would have the Tubes channel spring up only when
- # the Tube is offered.
- #
- # Anyway. Given the current implementation, they should be announced together.
- assert len(new_channel_details) == 2, unwrap(new_channel_details)
- found_tubes = False
- found_tube = False
- for path, details in new_channel_details:
- if details[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TUBES:
- found_tubes = True
- tubes_chan = bus.get_object(conn.bus_name, path)
- tubes_iface = dbus.Interface(tubes_chan, cs.CHANNEL_TYPE_TUBES)
- elif details[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_DBUS_TUBE:
- found_tube = True
- assert tube_path == path, (tube_path, path)
- else:
- assert False, (path, details)
- assert found_tube and found_tubes, unwrap(new_channel_details)
-
- # The tube's not offered, so it shouldn't be shown on the old interface.
- tubes = tubes_iface.ListTubes(byte_arrays=True)
- assert len(tubes) == 0, tubes
-
- tube_chan = bus.get_object(conn.bus_name, tube_path)
- tube_chan_iface = dbus.Interface(tube_chan, cs.CHANNEL)
- dbus_tube_iface = dbus.Interface(tube_chan, cs.CHANNEL_TYPE_DBUS_TUBE)
-
- # check State and Parameters
- props = tube_chan.GetAll(cs.CHANNEL_IFACE_TUBE, dbus_interface=cs.PROPERTIES_IFACE,
- byte_arrays=True)
- assert props['State'] == cs.TUBE_CHANNEL_STATE_NOT_OFFERED
-
- # check ServiceName and DBusNames
- props = tube_chan.GetAll(cs.CHANNEL_TYPE_DBUS_TUBE, dbus_interface=cs.PROPERTIES_IFACE)
- assert props['ServiceName'] == 'com.example.TestCase'
- assert props['DBusNames'] == {}
-
- # Only when we offer the tube should it appear on the Tubes channel and an
- # IQ be sent to Alice. We sync the stream to ensure the IQ would have
- # arrived if it had been sent.
- sync_stream(q, stream)
- call_async(q, dbus_tube_iface, 'OfferDBusTube', sample_parameters)
- offer_return_event, iq_event, new_tube_event, state_event = q.expect_many(
- EventPattern('dbus-return', method='OfferDBusTube'),
- EventPattern('stream-iq', to='alice at localhost/Test'),
- EventPattern('dbus-signal', signal='NewTube'),
- EventPattern('dbus-signal', signal='TubeChannelStateChanged'),
- )
-
- tube_address = offer_return_event.value[0]
- assert len(tube_address) > 0
-
- assert state_event.args[0] == cs.TUBE_CHANNEL_STATE_REMOTE_PENDING
-
- # Now the tube's been offered, it should be shown on the old interface
- tubes = tubes_iface.ListTubes(byte_arrays=True)
- assert len(tubes) == 1
- expected_tube = (None, self_handle, cs.TUBE_TYPE_DBUS, 'com.example.TestCase',
- sample_parameters, cs.TUBE_STATE_REMOTE_PENDING)
- t.check_tube_in_tubes(expected_tube, tubes)
-
- status = tube_chan.Get(cs.CHANNEL_IFACE_TUBE, 'State', dbus_interface=cs.PROPERTIES_IFACE)
- assert status == cs.TUBE_STATE_REMOTE_PENDING
-
- tube_chan_iface.Close()
-
- q.expect_many(
- EventPattern('dbus-signal', signal='Closed'),
- EventPattern('dbus-signal', signal='ChannelClosed'))
-
-def test(q, bus, conn, stream, bytestream_cls):
- conn.Connect()
-
- q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
-
- t.check_conn_properties(q, conn)
-
- self_handle = conn.GetSelfHandle()
- alice_handle = conn.RequestHandles(cs.HT_CONTACT, ["alice at localhost"])[0]
-
- # send Alice's presence
- caps = { 'ext': '', 'ver': '0.0.0',
- 'node': 'http://example.com/fake-client0' }
- presence = make_presence('alice at localhost/Test', 'test at localhost', caps)
- stream.send(presence)
-
- q.expect('dbus-signal', signal='PresencesChanged',
- args = [{alice_handle: (2L, u'available', u'')}])
-
- # reply to disco query
- event = q.expect('stream-iq', to='alice at localhost/Test', query_ns=ns.DISCO_INFO)
- stream.send(make_caps_disco_reply(stream, event.stanza, [ns.TUBES]))
-
- sync_stream(q, stream)
-
- offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle, bytestream_cls)
- offer_new_dbus_tube(q, bus, conn, stream, self_handle, alice_handle, bytestream_cls)
-
- # OK, we're done
- conn.Disconnect()
- q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
-
-if __name__ == '__main__':
- t.exec_tube_test(test)
diff --git a/tests/twisted/tubes/offer-private-dbus-tube.py b/tests/twisted/tubes/offer-private-dbus-tube.py
new file mode 100644
index 0000000..b0b8e57
--- /dev/null
+++ b/tests/twisted/tubes/offer-private-dbus-tube.py
@@ -0,0 +1,311 @@
+"""Test D-Bus private tube support"""
+
+import dbus
+from dbus.connection import Connection
+from dbus.lowlevel import SignalMessage
+
+from servicetest import call_async, EventPattern, unwrap
+from gabbletest import exec_test, make_result_iq, sync_stream
+import constants as cs
+import tubetestutil as t
+
+from twisted.words.xish import domish, xpath
+import ns
+from bytestream import parse_si_offer, create_si_reply
+
+sample_parameters = dbus.Dictionary({
+ 's': 'hello',
+ 'ay': dbus.ByteArray('hello'),
+ 'u': dbus.UInt32(123),
+ 'i': dbus.Int32(-123),
+ }, signature='sv')
+
+# FIXME: stolen from jingletest.py. Should be shared by all tests
+def make_presence(fromjid, tojid, caps=None):
+ el = domish.Element(('jabber:client', 'presence',))
+ el['from'] = fromjid
+ el['to'] = tojid
+
+ if caps:
+ cel = domish.Element(('http://jabber.org/protocol/caps', 'c'))
+ for key,value in caps.items():
+ cel[key] = value
+ el.addChild(cel)
+
+ return el
+
+def make_caps_disco_reply(stream, req, features):
+ iq = make_result_iq(stream, req)
+ query = iq.firstChildElement()
+
+ for f in features:
+ el = domish.Element((None, 'feature'))
+ el['var'] = f
+ query.addChild(el)
+
+ return iq
+
+def alice_accepts_tube(q, stream, iq_event, dbus_tube_id, bytestream_cls):
+ iq = iq_event.stanza
+
+ profile, dbus_stream_id, bytestreams = parse_si_offer(iq)
+
+ assert profile == ns.TUBES
+ assert bytestreams == [ns.BYTESTREAMS, ns.IBB]
+
+ tube_nodes = xpath.queryForNodes('/iq/si/tube[@xmlns="%s"]'
+ % ns.TUBES, iq)
+ assert len(tube_nodes) == 1
+ tube = tube_nodes[0]
+ tube['type'] = 'dbus'
+ assert tube['initiator'] == 'test at localhost'
+ assert tube['service'] == 'com.example.TestCase'
+ assert tube['id'] == str(dbus_tube_id)
+
+ params = {}
+ parameter_nodes = xpath.queryForNodes('/tube/parameters/parameter', tube)
+ for node in parameter_nodes:
+ assert node['name'] not in params
+ params[node['name']] = (node['type'], str(node))
+ assert params == {'ay': ('bytes', 'aGVsbG8='),
+ 's': ('str', 'hello'),
+ 'i': ('int', '-123'),
+ 'u': ('uint', '123'),
+ }
+
+ # Alice accepts the tube
+ bytestream = bytestream_cls(stream, q, dbus_stream_id, 'test at localhost/Resource',
+ 'alice at localhost/Test', False)
+
+ result, si = create_si_reply(stream, iq, bytestream.initiator, bytestream.get_ns())
+ si.addElement((ns.TUBES, 'tube'))
+ stream.send(result)
+
+ bytestream.wait_bytestream_open()
+
+ q.expect('dbus-signal', signal='TubeStateChanged',
+ args=[dbus_tube_id, cs.TUBE_STATE_OPEN])
+
+ return bytestream
+
+def send_dbus_message_to_alice(q, stream, dbus_tube_adr, bytestream):
+ tube = Connection(dbus_tube_adr)
+ signal = SignalMessage('/', 'foo.bar', 'baz')
+ signal.append(42, signature='u')
+ tube.send_message(signal)
+
+ binary = bytestream.get_data()
+
+ # little and big endian versions of: SIGNAL, NO_REPLY, protocol v1,
+ # 4-byte payload
+ assert binary.startswith('l\x04\x01\x01' '\x04\x00\x00\x00') or \
+ binary.startswith('B\x04\x01\x01' '\x00\x00\x00\x04')
+ # little and big endian versions of the 4-byte payload, UInt32(42)
+ assert (binary[0] == 'l' and binary.endswith('\x2a\x00\x00\x00')) or \
+ (binary[0] == 'B' and binary.endswith('\x00\x00\x00\x2a'))
+ # XXX: verify that it's actually in the "sender" slot, rather than just
+ # being in the message somewhere
+
+def offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle, bytestream_cls):
+ # request tubes channel (old API)
+ tubes_path = conn.RequestChannel(cs.CHANNEL_TYPE_TUBES, cs.HT_CONTACT,
+ alice_handle, True)
+ tubes_chan = bus.get_object(conn.bus_name, tubes_path)
+ tubes_iface = dbus.Interface(tubes_chan, cs.CHANNEL_TYPE_TUBES)
+ tubes_chan_iface = dbus.Interface(tubes_chan, cs.CHANNEL)
+
+ # Exercise basic Channel Properties from spec 0.17.7
+ channel_props = tubes_chan.GetAll(cs.CHANNEL, dbus_interface=cs.PROPERTIES_IFACE)
+ assert channel_props.get('TargetHandle') == alice_handle,\
+ (channel_props.get('TargetHandle'), alice_handle)
+ assert channel_props.get('TargetHandleType') == cs.HT_CONTACT,\
+ channel_props.get('TargetHandleType')
+ assert channel_props.get('ChannelType') == cs.CHANNEL_TYPE_TUBES,\
+ channel_props.get('ChannelType')
+ assert 'Interfaces' in channel_props, channel_props
+ assert channel_props['Interfaces'] == [], channel_props['Interfaces']
+ assert channel_props['TargetID'] == 'alice at localhost', channel_props['TargetID']
+ assert channel_props['Requested'] == True
+ assert channel_props['InitiatorID'] == 'test at localhost'
+ assert channel_props['InitiatorHandle'] == conn.GetSelfHandle()
+
+ # Offer a D-Bus tube using old API
+ call_async(q, tubes_iface, 'OfferDBusTube',
+ 'com.example.TestCase', sample_parameters)
+
+ new_tube_event, iq_event, offer_return_event = \
+ q.expect_many(
+ EventPattern('dbus-signal', signal='NewTube'),
+ EventPattern('stream-iq', to='alice at localhost/Test'),
+ EventPattern('dbus-return', method='OfferDBusTube'))
+
+ # handle new_tube_event
+ dbus_tube_id = new_tube_event.args[0]
+ assert new_tube_event.args[1] == self_handle
+ assert new_tube_event.args[2] == 0 # DBUS
+ assert new_tube_event.args[3] == 'com.example.TestCase'
+ assert new_tube_event.args[4] == sample_parameters
+ assert new_tube_event.args[5] == cs.TUBE_STATE_REMOTE_PENDING
+
+ # handle offer_return_event
+ assert offer_return_event.value[0] == dbus_tube_id
+
+ tubes = tubes_iface.ListTubes(byte_arrays=True)
+ assert len(tubes) == 1
+ expected_tube = (dbus_tube_id, self_handle, cs.TUBE_TYPE_DBUS,
+ 'com.example.TestCase', sample_parameters, cs.TUBE_STATE_REMOTE_PENDING)
+ t.check_tube_in_tubes(expected_tube, tubes)
+
+ bytestream = alice_accepts_tube(q, stream, iq_event, dbus_tube_id, bytestream_cls)
+
+ dbus_tube_adr = tubes_iface.GetDBusTubeAddress(dbus_tube_id)
+ send_dbus_message_to_alice(q, stream, dbus_tube_adr, bytestream)
+
+ # close the tube
+ tubes_iface.CloseTube(dbus_tube_id)
+ q.expect('dbus-signal', signal='TubeClosed', args=[dbus_tube_id])
+
+ # and close the tubes channel
+ tubes_chan_iface.Close()
+ q.expect('dbus-signal', signal='Closed')
+
+
+def offer_new_dbus_tube(q, bus, conn, stream, self_handle, alice_handle, bytestream_cls):
+ requestotron = dbus.Interface(conn, cs.CONN_IFACE_REQUESTS)
+
+ # Offer a tube to Alice (new API)
+
+ call_async(q, requestotron, 'CreateChannel',
+ {cs.CHANNEL_TYPE: cs.CHANNEL_TYPE_DBUS_TUBE,
+ cs.TARGET_HANDLE_TYPE: cs.HT_CONTACT,
+ cs.TARGET_ID: 'alice at localhost',
+ cs.DBUS_TUBE_SERVICE_NAME: 'com.example.TestCase'
+ }, byte_arrays=True)
+ cc_ret, nc = q.expect_many(
+ EventPattern('dbus-return', method='CreateChannel'),
+ EventPattern('dbus-signal', signal='NewChannels'),
+ )
+ tube_path, tube_props = cc_ret.value
+ new_channel_details = nc.args[0]
+
+ # check tube channel properties
+ assert tube_props[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_DBUS_TUBE
+ assert tube_props[cs.INTERFACES] == [cs.CHANNEL_IFACE_TUBE]
+ assert tube_props[cs.TARGET_HANDLE_TYPE] == cs.HT_CONTACT
+ assert tube_props[cs.TARGET_HANDLE] == alice_handle
+ assert tube_props[cs.TARGET_ID] == 'alice at localhost'
+ assert tube_props[cs.REQUESTED] == True
+ assert tube_props[cs.INITIATOR_HANDLE] == self_handle
+ assert tube_props[cs.INITIATOR_ID] == "test at localhost"
+ assert tube_props[cs.DBUS_TUBE_SERVICE_NAME] == 'com.example.TestCase'
+ assert cs.DBUS_TUBE_DBUS_NAMES not in tube_props
+ assert cs.TUBE_PARAMETERS not in tube_props
+ assert cs.TUBE_STATE not in tube_props
+
+ # Under the current implementation, creating a new-style Tube channel
+ # ensures that an old-style Tubes channel exists, even though Tube channels
+ # aren't visible on the Tubes channel until they're offered. Another
+ # correct implementation would have the Tubes channel spring up only when
+ # the Tube is offered.
+ #
+ # Anyway. Given the current implementation, they should be announced together.
+ assert len(new_channel_details) == 2, unwrap(new_channel_details)
+ found_tubes = False
+ found_tube = False
+ for path, details in new_channel_details:
+ if details[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_TUBES:
+ found_tubes = True
+ tubes_chan = bus.get_object(conn.bus_name, path)
+ tubes_iface = dbus.Interface(tubes_chan, cs.CHANNEL_TYPE_TUBES)
+ elif details[cs.CHANNEL_TYPE] == cs.CHANNEL_TYPE_DBUS_TUBE:
+ found_tube = True
+ assert tube_path == path, (tube_path, path)
+ else:
+ assert False, (path, details)
+ assert found_tube and found_tubes, unwrap(new_channel_details)
+
+ # The tube's not offered, so it shouldn't be shown on the old interface.
+ tubes = tubes_iface.ListTubes(byte_arrays=True)
+ assert len(tubes) == 0, tubes
+
+ tube_chan = bus.get_object(conn.bus_name, tube_path)
+ tube_chan_iface = dbus.Interface(tube_chan, cs.CHANNEL)
+ dbus_tube_iface = dbus.Interface(tube_chan, cs.CHANNEL_TYPE_DBUS_TUBE)
+
+ # check State and Parameters
+ props = tube_chan.GetAll(cs.CHANNEL_IFACE_TUBE, dbus_interface=cs.PROPERTIES_IFACE,
+ byte_arrays=True)
+ assert props['State'] == cs.TUBE_CHANNEL_STATE_NOT_OFFERED
+
+ # check ServiceName and DBusNames
+ props = tube_chan.GetAll(cs.CHANNEL_TYPE_DBUS_TUBE, dbus_interface=cs.PROPERTIES_IFACE)
+ assert props['ServiceName'] == 'com.example.TestCase'
+ assert props['DBusNames'] == {}
+
+ # Only when we offer the tube should it appear on the Tubes channel and an
+ # IQ be sent to Alice. We sync the stream to ensure the IQ would have
+ # arrived if it had been sent.
+ sync_stream(q, stream)
+ call_async(q, dbus_tube_iface, 'OfferDBusTube', sample_parameters)
+ offer_return_event, iq_event, new_tube_event, state_event = q.expect_many(
+ EventPattern('dbus-return', method='OfferDBusTube'),
+ EventPattern('stream-iq', to='alice at localhost/Test'),
+ EventPattern('dbus-signal', signal='NewTube'),
+ EventPattern('dbus-signal', signal='TubeChannelStateChanged'),
+ )
+
+ tube_address = offer_return_event.value[0]
+ assert len(tube_address) > 0
+
+ assert state_event.args[0] == cs.TUBE_CHANNEL_STATE_REMOTE_PENDING
+
+ # Now the tube's been offered, it should be shown on the old interface
+ tubes = tubes_iface.ListTubes(byte_arrays=True)
+ assert len(tubes) == 1
+ expected_tube = (None, self_handle, cs.TUBE_TYPE_DBUS, 'com.example.TestCase',
+ sample_parameters, cs.TUBE_STATE_REMOTE_PENDING)
+ t.check_tube_in_tubes(expected_tube, tubes)
+
+ status = tube_chan.Get(cs.CHANNEL_IFACE_TUBE, 'State', dbus_interface=cs.PROPERTIES_IFACE)
+ assert status == cs.TUBE_STATE_REMOTE_PENDING
+
+ tube_chan_iface.Close()
+
+ q.expect_many(
+ EventPattern('dbus-signal', signal='Closed'),
+ EventPattern('dbus-signal', signal='ChannelClosed'))
+
+def test(q, bus, conn, stream, bytestream_cls):
+ conn.Connect()
+
+ q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])
+
+ t.check_conn_properties(q, conn)
+
+ self_handle = conn.GetSelfHandle()
+ alice_handle = conn.RequestHandles(cs.HT_CONTACT, ["alice at localhost"])[0]
+
+ # send Alice's presence
+ caps = { 'ext': '', 'ver': '0.0.0',
+ 'node': 'http://example.com/fake-client0' }
+ presence = make_presence('alice at localhost/Test', 'test at localhost', caps)
+ stream.send(presence)
+
+ q.expect('dbus-signal', signal='PresencesChanged',
+ args = [{alice_handle: (2L, u'available', u'')}])
+
+ # reply to disco query
+ event = q.expect('stream-iq', to='alice at localhost/Test', query_ns=ns.DISCO_INFO)
+ stream.send(make_caps_disco_reply(stream, event.stanza, [ns.TUBES]))
+
+ sync_stream(q, stream)
+
+ offer_old_dbus_tube(q, bus, conn, stream, self_handle, alice_handle, bytestream_cls)
+ offer_new_dbus_tube(q, bus, conn, stream, self_handle, alice_handle, bytestream_cls)
+
+ # OK, we're done
+ conn.Disconnect()
+ q.expect('dbus-signal', signal='StatusChanged', args=[2, 1])
+
+if __name__ == '__main__':
+ t.exec_tube_test(test)
--
1.5.6.5
More information about the telepathy-commits
mailing list