From 90b14e48ce43891c523b56ff2054787de6352024 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 25 Sep 2013 18:16:13 +0100 Subject: [PATCH 3/3] Sync servicetest, constants with the version merged into Gabble --- tests/twisted/account-manager/auto-connect.py | 12 +- tests/twisted/account-manager/avatar-persist.py | 2 +- tests/twisted/account-manager/avatar-refresh.py | 2 +- .../account-manager/backend-makes-changes.py | 20 +- tests/twisted/account-manager/connectivity.py | 6 +- tests/twisted/account-manager/crashy-cm.py | 6 +- .../twisted/account-manager/create-auto-connect.py | 4 +- .../account-manager/create-with-properties.py | 8 +- .../twisted/account-manager/enable-auto-connect.py | 4 +- tests/twisted/account-manager/enable.py | 4 +- tests/twisted/account-manager/irc.py | 2 +- tests/twisted/account-manager/make-valid.py | 10 +- tests/twisted/account-manager/presence.py | 8 +- tests/twisted/account-manager/reconnect.py | 12 +- .../account-manager/recover-from-disconnect.py | 16 +- tests/twisted/account-manager/req-conn-fails.py | 4 +- tests/twisted/account-manager/request-online.py | 10 +- tests/twisted/account-manager/server-drops-us.py | 10 +- tests/twisted/account-manager/update-parameters.py | 2 +- tests/twisted/capabilities/contact-caps.py | 2 +- tests/twisted/constants.py | 536 ++++++++++++++++++--- tests/twisted/dbus-account-plugin.c | 4 +- tests/twisted/dispatcher/already-has-channel.py | 2 +- tests/twisted/dispatcher/already-has-obsolete.py | 2 +- tests/twisted/dispatcher/capture-bundle.py | 2 +- tests/twisted/dispatcher/connect-for-request.py | 10 +- tests/twisted/dispatcher/create-at-startup.py | 2 +- tests/twisted/dispatcher/create-text.py | 2 +- .../dispatcher/dispatch-before-connected.py | 2 +- tests/twisted/dispatcher/exploding-bundles.py | 2 +- .../twisted/dispatcher/recover-from-disconnect.py | 8 +- .../twisted/dispatcher/request-disabled-account.py | 4 +- tests/twisted/mctest.py | 34 +- tests/twisted/servicetest.py | 357 ++++++++++---- 34 files changed, 836 insertions(+), 275 deletions(-) diff --git a/tests/twisted/account-manager/auto-connect.py b/tests/twisted/account-manager/auto-connect.py index a623902..c8b9184 100644 --- a/tests/twisted/account-manager/auto-connect.py +++ b/tests/twisted/account-manager/auto-connect.py @@ -124,7 +124,7 @@ def test(q, bus, unused, **kwargs): assertEquals({}, prop_changed.args[0].get('ConnectionErrorDetails')) assertEquals(cs.CONN_STATUS_CONNECTING, prop_changed.args[0].get('ConnectionStatus')) - assertEquals(cs.CONN_STATUS_REASON_REQUESTED, + assertEquals(cs.CSR_REQUESTED, prop_changed.args[0].get('ConnectionStatusReason')) q.dbus_return(request_conn.message, conn.bus_name, conn.object_path, @@ -147,16 +147,16 @@ def test(q, bus, unused, **kwargs): assertEquals({}, prop_changed.args[0].get('ConnectionErrorDetails')) assertEquals(cs.CONN_STATUS_CONNECTING, prop_changed.args[0].get('ConnectionStatus')) - assertEquals(cs.CONN_STATUS_REASON_REQUESTED, + assertEquals(cs.CSR_REQUESTED, prop_changed.args[0].get('ConnectionStatusReason')) props = account.GetAll(cs.ACCOUNT, dbus_interface=cs.PROPERTIES_IFACE) assert props['Connection'] == conn.object_path assert props['ConnectionStatus'] == cs.CONN_STATUS_CONNECTING - assert props['ConnectionStatusReason'] == cs.CONN_STATUS_REASON_REQUESTED + assert props['ConnectionStatusReason'] == cs.CSR_REQUESTED print "becoming connected" - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) set_aliases, set_presence, set_avatar, prop_changed = q.expect_many( EventPattern('dbus-method-call', @@ -183,11 +183,11 @@ def test(q, bus, unused, **kwargs): assertEquals({}, prop_changed.args[0].get('ConnectionErrorDetails')) assertEquals(cs.CONN_STATUS_CONNECTED, prop_changed.args[0].get('ConnectionStatus')) - assertEquals(cs.CONN_STATUS_REASON_REQUESTED, + assertEquals(cs.CSR_REQUESTED, prop_changed.args[0].get('ConnectionStatusReason')) assert account.Get(cs.ACCOUNT, 'CurrentPresence', - dbus_interface=cs.PROPERTIES_IFACE) == (cs.PRESENCE_TYPE_AVAILABLE, + dbus_interface=cs.PROPERTIES_IFACE) == (cs.PRESENCE_AVAILABLE, 'available', 'My vision is augmented') q.dbus_return(set_aliases.message, signature='') diff --git a/tests/twisted/account-manager/avatar-persist.py b/tests/twisted/account-manager/avatar-persist.py index 7dedb18..195c80a 100644 --- a/tests/twisted/account-manager/avatar-persist.py +++ b/tests/twisted/account-manager/avatar-persist.py @@ -106,7 +106,7 @@ def test(q, bus, unused, **kwargs): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True, interface=cs.CONN) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) # We haven't changed the avatar since we last signed in, so we don't set # it - on the contrary, we pick up the remote avatar (which has changed diff --git a/tests/twisted/account-manager/avatar-refresh.py b/tests/twisted/account-manager/avatar-refresh.py index 817a623..e044eb0 100644 --- a/tests/twisted/account-manager/avatar-refresh.py +++ b/tests/twisted/account-manager/avatar-refresh.py @@ -100,7 +100,7 @@ def test(q, bus, unused, **kwargs): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True, interface=cs.CONN) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) _, _, e = q.expect_many( EventPattern('dbus-method-call', diff --git a/tests/twisted/account-manager/backend-makes-changes.py b/tests/twisted/account-manager/backend-makes-changes.py index 89eb4c1..30bb0ef 100644 --- a/tests/twisted/account-manager/backend-makes-changes.py +++ b/tests/twisted/account-manager/backend-makes-changes.py @@ -34,7 +34,7 @@ def test(q, bus, mc, fake_accounts_service=None, **kwargs): {}, # attr flags {'account': 'ezio@firenze.fic', 'password': 'nothing is true'}, {}, # untyped parameters - {'password': cs.PARAM_FLAG_SECRET}) # param flags + {'password': cs.PARAM_SECRET}) # param flags q.expect_many( EventPattern('dbus-signal', path=cs.TEST_DBUS_ACCOUNT_SERVICE_PATH, @@ -47,7 +47,7 @@ def test(q, bus, mc, fake_accounts_service=None, **kwargs): {'account': 'ezio@firenze.fic', 'password': 'nothing is true'}, {}, - {'account': 0, 'password': cs.PARAM_FLAG_SECRET}]), + {'account': 0, 'password': cs.PARAM_SECRET}]), EventPattern('dbus-signal', path=cs.AM_PATH, signal='AccountValidityChanged', @@ -184,14 +184,14 @@ def test(q, bus, mc, fake_accounts_service=None, **kwargs): account.Properties.Get(cs.ACCOUNT, 'Supersedes')) fake_accounts_service.update_attributes(account_tail, - {'AutomaticPresence': (dbus.UInt32(cs.PRESENCE_TYPE_HIDDEN), 'hidden', + {'AutomaticPresence': (dbus.UInt32(cs.PRESENCE_HIDDEN), 'hidden', 'in a haystack or something')}) q.expect_many( EventPattern('dbus-signal', path=cs.TEST_DBUS_ACCOUNT_SERVICE_PATH, signal='AttributesChanged', args=[account_tail, - {'AutomaticPresence': (cs.PRESENCE_TYPE_HIDDEN, + {'AutomaticPresence': (cs.PRESENCE_HIDDEN, 'hidden', 'in a haystack or something')}, {'AutomaticPresence': 0}, @@ -201,14 +201,14 @@ def test(q, bus, mc, fake_accounts_service=None, **kwargs): signal='AccountPropertyChanged', interface=cs.ACCOUNT, args=[{'AutomaticPresence': - (cs.PRESENCE_TYPE_HIDDEN, 'hidden', + (cs.PRESENCE_HIDDEN, 'hidden', 'in a haystack or something')}]), EventPattern('dbus-signal', path=cs.TEST_DBUS_ACCOUNT_PLUGIN_PATH, signal='AttributeChanged', args=[account_path, 'AutomaticPresence']), ) - assertEquals((cs.PRESENCE_TYPE_HIDDEN, 'hidden', + assertEquals((cs.PRESENCE_HIDDEN, 'hidden', 'in a haystack or something'), account.Properties.Get(cs.ACCOUNT, 'AutomaticPresence')) @@ -276,13 +276,13 @@ def test(q, bus, mc, fake_accounts_service=None, **kwargs): account.Properties.Get(cs.ACCOUNT, 'Service')) fake_accounts_service.update_parameters(account_tail, { - 'password': 'high profile'}, flags={'password': cs.PARAM_FLAG_SECRET}) + 'password': 'high profile'}, flags={'password': cs.PARAM_SECRET}) q.expect_many( EventPattern('dbus-signal', path=cs.TEST_DBUS_ACCOUNT_SERVICE_PATH, signal='ParametersChanged', args=[account_tail, {'password': 'high profile'}, - {}, {'password': cs.PARAM_FLAG_SECRET}, []]), + {}, {'password': cs.PARAM_SECRET}, []]), EventPattern('dbus-signal', path=account_path, signal='AccountPropertyChanged', @@ -296,13 +296,13 @@ def test(q, bus, mc, fake_accounts_service=None, **kwargs): ) fake_accounts_service.update_parameters(account_tail, untyped={ - 'password': r'\\\n'}, flags={'password': cs.PARAM_FLAG_SECRET}) + 'password': r'\\\n'}, flags={'password': cs.PARAM_SECRET}) q.expect_many( EventPattern('dbus-signal', path=cs.TEST_DBUS_ACCOUNT_SERVICE_PATH, signal='ParametersChanged', args=[account_tail, {}, {'password': r'\\\n'}, - {'password': cs.PARAM_FLAG_SECRET}, []]), + {'password': cs.PARAM_SECRET}, []]), EventPattern('dbus-signal', path=account_path, signal='AccountPropertyChanged', diff --git a/tests/twisted/account-manager/connectivity.py b/tests/twisted/account-manager/connectivity.py index 8d80c1d..95fac29 100644 --- a/tests/twisted/account-manager/connectivity.py +++ b/tests/twisted/account-manager/connectivity.py @@ -56,13 +56,13 @@ def test(q, bus, mc): q.forbid_events(request_connection_event) account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', 'hlaghalgh')) + (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'hlaghalgh')) # Turn the account on, re-request an online presence, and even tell it to # connect automatically, to check that none of these make it sign in. call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'Enabled', True) q.expect('dbus-return', method='Set') - requested_presence = (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', 'gtfo') + requested_presence = (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'gtfo') call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'RequestedPresence', requested_presence) q.expect('dbus-return', method='Set') @@ -149,7 +149,7 @@ def test(q, bus, mc): # connection comes back up the account should not be brought back online. q.forbid_events(request_connection_event) account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '')) + (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) mc.connectivity.go_online() # Make sure MC has noticed that the network connection has come back. sync_connectivity_state(mc) diff --git a/tests/twisted/account-manager/crashy-cm.py b/tests/twisted/account-manager/crashy-cm.py index 2eebeb8..531c41a 100644 --- a/tests/twisted/account-manager/crashy-cm.py +++ b/tests/twisted/account-manager/crashy-cm.py @@ -45,7 +45,7 @@ def test(q, bus, mc): # Set online presence presence = dbus.Struct( - (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', 'Fixing MC bugs'), + (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Fixing MC bugs'), signature='uss') account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', presence) @@ -65,7 +65,7 @@ def test(q, bus, mc): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) # CM crashes conn.release_name() @@ -80,7 +80,7 @@ def test(q, bus, mc): assertEquals('/', changed['Connection']) assertEquals(cs.CONN_STATUS_DISCONNECTED, changed['ConnectionStatus']) # In the absence of a better code, None will have to do. - assertEquals(cs.CONN_STATUS_REASON_NONE, changed['ConnectionStatusReason']) + assertEquals(cs.CSR_NONE_SPECIFIED, changed['ConnectionStatusReason']) # And NoReply will do as “it crashed”. assertEquals(cs.DBUS_ERROR_NO_REPLY, changed['ConnectionError']) diff --git a/tests/twisted/account-manager/create-auto-connect.py b/tests/twisted/account-manager/create-auto-connect.py index fa2cb47..54acc27 100644 --- a/tests/twisted/account-manager/create-auto-connect.py +++ b/tests/twisted/account-manager/create-auto-connect.py @@ -36,11 +36,11 @@ def test(q, bus, mc): # Ensure that it's enabled but has offline RP call_async(q, account_props, 'Set', cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '')) + (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) q.expect('dbus-return', method='Set') call_async(q, account_props, 'Set', cs.ACCOUNT, 'AutomaticPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Testing automatic presence')) q.expect('dbus-return', method='Set') q.expect('dbus-signal', signal='AccountPropertyChanged', diff --git a/tests/twisted/account-manager/create-with-properties.py b/tests/twisted/account-manager/create-with-properties.py index 6e20880..6da44aa 100644 --- a/tests/twisted/account-manager/create-with-properties.py +++ b/tests/twisted/account-manager/create-with-properties.py @@ -60,10 +60,10 @@ def test(q, bus, mc): creation_properties = dbus.Dictionary({ cs.ACCOUNT + '.Enabled': True, cs.ACCOUNT + '.AutomaticPresence': dbus.Struct(( - dbus.UInt32(cs.PRESENCE_TYPE_BUSY), + dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Exploding'), signature='uss'), cs.ACCOUNT + '.RequestedPresence': dbus.Struct(( - dbus.UInt32(cs.PRESENCE_TYPE_AWAY), + dbus.UInt32(cs.PRESENCE_AWAY), 'away', 'Respawning'), signature='uss'), cs.ACCOUNT + '.Icon': 'quake3arena', cs.ACCOUNT + '.Nickname': 'AnArKi', @@ -107,10 +107,10 @@ def test(q, bus, mc): account_props = dbus.Interface(account, cs.PROPERTIES_IFACE) properties = account_props.GetAll(cs.ACCOUNT) - assert properties.get('AutomaticPresence') == (cs.PRESENCE_TYPE_BUSY, + assert properties.get('AutomaticPresence') == (cs.PRESENCE_BUSY, 'busy', 'Exploding'), \ properties.get('AutomaticPresence') - assert properties.get('RequestedPresence') == (cs.PRESENCE_TYPE_AWAY, + assert properties.get('RequestedPresence') == (cs.PRESENCE_AWAY, 'away', 'Respawning'), \ properties.get('RequestedPresence') assert properties.get('ConnectAutomatically') == True, \ diff --git a/tests/twisted/account-manager/enable-auto-connect.py b/tests/twisted/account-manager/enable-auto-connect.py index 2cb91c3..c5f9899 100644 --- a/tests/twisted/account-manager/enable-auto-connect.py +++ b/tests/twisted/account-manager/enable-auto-connect.py @@ -36,11 +36,11 @@ def test(q, bus, mc): # Ensure that it's enabled but has offline RP call_async(q, account_props, 'Set', cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '')) + (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) q.expect('dbus-return', method='Set') call_async(q, account_props, 'Set', cs.ACCOUNT, 'AutomaticPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Testing automatic presence')) q.expect('dbus-return', method='Set') q.expect('dbus-signal', signal='AccountPropertyChanged', diff --git a/tests/twisted/account-manager/enable.py b/tests/twisted/account-manager/enable.py index 50e489d..14525ff 100644 --- a/tests/twisted/account-manager/enable.py +++ b/tests/twisted/account-manager/enable.py @@ -34,7 +34,7 @@ def test(q, bus, mc): account_props = dbus.Interface(account, cs.PROPERTIES_IFACE) call_async(q, account_props, 'Set', cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '')) + (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) q.expect('dbus-return', method='Set') call_async(q, account_props, 'Set', cs.ACCOUNT, 'Enabled', False) @@ -45,7 +45,7 @@ def test(q, bus, mc): q.expect('dbus-return', method='Set') call_async(q, account_props, 'Set', cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', 'Testing Enabled')) + (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Testing Enabled')) q.expect('dbus-return', method='Set') # Go online by setting Enabled diff --git a/tests/twisted/account-manager/irc.py b/tests/twisted/account-manager/irc.py index 6575aed..4c28e97 100644 --- a/tests/twisted/account-manager/irc.py +++ b/tests/twisted/account-manager/irc.py @@ -60,7 +60,7 @@ def test(q, bus, mc): interface=cs.ACCOUNT, predicate=lambda e: e.args[0].get('CurrentPresence') == - (cs.PRESENCE_TYPE_UNSET, '', '')), + (cs.PRESENCE_UNSET, '', '')), ] conn, get_aliases, set_aliases, _ = enable_fakecm_account(q, bus, mc, diff --git a/tests/twisted/account-manager/make-valid.py b/tests/twisted/account-manager/make-valid.py index 7c1df85..33582c5 100644 --- a/tests/twisted/account-manager/make-valid.py +++ b/tests/twisted/account-manager/make-valid.py @@ -169,7 +169,7 @@ def test(q, bus, unused, **kwargs): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True, interface=cs.CONN) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) set_presence, e = q.expect_many( EventPattern('dbus-method-call', path=conn.object_path, @@ -181,7 +181,7 @@ def test(q, bus, unused, **kwargs): and e.args[0]['CurrentPresence'][2] != ''), ) - assert e.args[0]['CurrentPresence'] == (cs.PRESENCE_TYPE_AVAILABLE, + assert e.args[0]['CurrentPresence'] == (cs.PRESENCE_AVAILABLE, 'available', 'My vision is augmented') # Request an online presence on account 2, then make it valid @@ -191,7 +191,7 @@ def test(q, bus, unused, **kwargs): account_path = (cs.tp_path_prefix + '/Account/' + account2_id) account = bus.get_object(cs.MC, account_path) - requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_BUSY), + requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Talking to Illuminati')) account.Set(cs.ACCOUNT, 'RequestedPresence', dbus.Struct(requested_presence, variant_level=1), @@ -221,7 +221,7 @@ def test(q, bus, unused, **kwargs): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True, interface=cs.CONN) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) set_presence = q.expect('dbus-method-call', path=conn.object_path, interface=cs.CONN_IFACE_SIMPLE_PRESENCE, method='SetPresence', @@ -232,7 +232,7 @@ def test(q, bus, unused, **kwargs): predicate=lambda e: 'CurrentPresence' in e.args[0] and e.args[0]['CurrentPresence'][1] == 'busy') - assert e.args[0]['CurrentPresence'] == (cs.PRESENCE_TYPE_BUSY, + assert e.args[0]['CurrentPresence'] == (cs.PRESENCE_BUSY, 'busy', 'Talking to Illuminati') if __name__ == '__main__': diff --git a/tests/twisted/account-manager/presence.py b/tests/twisted/account-manager/presence.py index 5577f5a..d7e30e0 100755 --- a/tests/twisted/account-manager/presence.py +++ b/tests/twisted/account-manager/presence.py @@ -30,11 +30,11 @@ def test(q, bus, mc): "password": "ionstorm"}, signature='sv') (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params) - presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Fighting conspiracies'), signature='uss') def mk_offline(message=''): - return dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', + return dbus.Struct((dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', message), signature='uss') offline = mk_offline() @@ -122,7 +122,7 @@ def test(q, bus, mc): 'Get(Statuses)[2]', 'SetPresence[2]'], log # Change requested presence after going online - presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_AWAY), 'away', + presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_AWAY), 'away', 'In Hong Kong'), signature='uss') call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'RequestedPresence', presence) @@ -151,7 +151,7 @@ def test(q, bus, mc): predicate=lambda e: e.args[0].get('RequestedPresence') is not None)] q.forbid_events(events) - presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_AWAY), 'away', + presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_AWAY), 'away', 'In Hong Kong'), signature='uss') call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'RequestedPresence', presence) diff --git a/tests/twisted/account-manager/reconnect.py b/tests/twisted/account-manager/reconnect.py index 44af410..cf27a42 100644 --- a/tests/twisted/account-manager/reconnect.py +++ b/tests/twisted/account-manager/reconnect.py @@ -51,7 +51,7 @@ def test(q, bus, mc): dbus_interface=cs.PROPERTIES_IFACE) q.expect('dbus-return', method='Set') - requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_AVAILABLE), + requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_AVAILABLE), dbus.String(u'available'), dbus.String(u''))) call_async(q, account, 'Set', cs.ACCOUNT, 'RequestedPresence', requested_presence, @@ -65,7 +65,7 @@ def test(q, bus, mc): # While we want to be offline but the account is enabled, Reconnect is # still a no-op. - requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), + requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_OFFLINE), dbus.String(u'offline'), dbus.String(u''))) call_async(q, account, 'Set', cs.ACCOUNT, 'RequestedPresence', requested_presence, @@ -98,7 +98,7 @@ def test(q, bus, mc): q.unforbid_events(looks_like_reconnection) - requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_AVAILABLE), + requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_AVAILABLE), dbus.String(u'brb'), dbus.String(u'Be back soon!'))) account.Set(cs.ACCOUNT, 'RequestedPresence', requested_presence, @@ -131,7 +131,7 @@ def test(q, bus, mc): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) # Assert that the NormalizedName is harvested from the Connection at some # point @@ -180,10 +180,10 @@ def test(q, bus, mc): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) # Put the account offline - requested_presence = (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '') + requested_presence = (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '') account.Set(cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) diff --git a/tests/twisted/account-manager/recover-from-disconnect.py b/tests/twisted/account-manager/recover-from-disconnect.py index 5cfe868..b808321 100644 --- a/tests/twisted/account-manager/recover-from-disconnect.py +++ b/tests/twisted/account-manager/recover-from-disconnect.py @@ -38,7 +38,7 @@ def test(q, bus, mc): call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'Enabled', True) # Set online presence - presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Fixing MC bugs'), signature='uss') call_async(q, account.Properties, 'Set', cs.ACCOUNT, 'RequestedPresence', presence) @@ -61,7 +61,7 @@ def test(q, bus, mc): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) q.expect('dbus-method-call', interface=cs.CONN_IFACE_SIMPLE_PRESENCE, @@ -73,7 +73,7 @@ def test(q, bus, mc): conn.ConnectionError('com.example.My.Network.Is.Full.Of.Eels', {'eels': 23, 'capacity': 23, 'debug-message': 'Too many eels'}) conn.StatusChanged(cs.CONN_STATUS_DISCONNECTED, - cs.CONN_STATUS_REASON_NETWORK_ERROR) + cs.CSR_NETWORK_ERROR) # MC reconnects. This time, we expect it to have deleted the 'register' # parameter. @@ -106,7 +106,7 @@ def test(q, bus, mc): disconnected.args[0].get('ConnectionErrorDetails')) assertEquals(cs.CONN_STATUS_DISCONNECTED, disconnected.args[0].get('ConnectionStatus')) - assertEquals(cs.CONN_STATUS_REASON_NETWORK_ERROR, + assertEquals(cs.CSR_NETWORK_ERROR, disconnected.args[0].get('ConnectionStatusReason')) assertEquals('/', connecting.args[0].get('Connection')) @@ -117,7 +117,7 @@ def test(q, bus, mc): connecting.args[0].get('ConnectionErrorDetails')) assertEquals(cs.CONN_STATUS_CONNECTING, connecting.args[0].get('ConnectionStatus')) - assertEquals(cs.CONN_STATUS_REASON_REQUESTED, + assertEquals(cs.CSR_REQUESTED, connecting.args[0].get('ConnectionStatusReason')) # The object path needs to be different from the first simulated @@ -150,7 +150,7 @@ def test(q, bus, mc): connecting.args[0].get('ConnectionErrorDetails')) assertEquals(cs.CONN_STATUS_CONNECTING, connecting.args[0].get('ConnectionStatus')) - assertEquals(cs.CONN_STATUS_REASON_REQUESTED, + assertEquals(cs.CSR_REQUESTED, connecting.args[0].get('ConnectionStatusReason')) assertEquals('com.example.My.Network.Is.Full.Of.Eels', @@ -160,7 +160,7 @@ def test(q, bus, mc): account.Properties.Get(cs.ACCOUNT, 'ConnectionErrorDetails')) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) connected, _ = q.expect_many( EventPattern('dbus-signal', signal='AccountPropertyChanged', @@ -180,7 +180,7 @@ def test(q, bus, mc): assertEquals({}, connected.args[0].get('ConnectionErrorDetails')) assertEquals(cs.CONN_STATUS_CONNECTED, connected.args[0].get('ConnectionStatus')) - assertEquals(cs.CONN_STATUS_REASON_REQUESTED, + assertEquals(cs.CSR_REQUESTED, connected.args[0].get('ConnectionStatusReason')) assertEquals('', account.Properties.Get(cs.ACCOUNT, 'ConnectionError')) diff --git a/tests/twisted/account-manager/req-conn-fails.py b/tests/twisted/account-manager/req-conn-fails.py index bc3f01a..632504e 100644 --- a/tests/twisted/account-manager/req-conn-fails.py +++ b/tests/twisted/account-manager/req-conn-fails.py @@ -37,7 +37,7 @@ def test(q, bus, mc): # Set online presence presence = dbus.Struct( - (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', 'Fixing MC bugs'), + (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Fixing MC bugs'), signature='uss') account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', presence) @@ -56,7 +56,7 @@ def test(q, bus, mc): changed, = e.args assertEquals('/', changed['Connection']) assertEquals(cs.CONN_STATUS_DISCONNECTED, changed['ConnectionStatus']) - assertEquals(cs.CONN_STATUS_REASON_NONE, changed['ConnectionStatusReason']) + assertEquals(cs.CSR_NONE_SPECIFIED, changed['ConnectionStatusReason']) assertEquals(cs.NOT_IMPLEMENTED, changed['ConnectionError']) if __name__ == '__main__': diff --git a/tests/twisted/account-manager/request-online.py b/tests/twisted/account-manager/request-online.py index 3d8a601..deea79c 100644 --- a/tests/twisted/account-manager/request-online.py +++ b/tests/twisted/account-manager/request-online.py @@ -59,7 +59,7 @@ def test(q, bus, mc): # The spec says it should be (Offline, "", "") but I don't think the # strings really matter. If anything, the second one should start out at # "offline". - assertEquals(cs.PRESENCE_TYPE_OFFLINE, props['CurrentPresence'][0]) + assertEquals(cs.PRESENCE_OFFLINE, props['CurrentPresence'][0]) # Enable the account account.Set(cs.ACCOUNT, 'Enabled', True, @@ -73,7 +73,7 @@ def test(q, bus, mc): assert props['Enabled'] assert props['Valid'] # Ditto above re. string fields. - assertEquals(cs.PRESENCE_TYPE_OFFLINE, props['CurrentPresence'][0]) + assertEquals(cs.PRESENCE_OFFLINE, props['CurrentPresence'][0]) # Go online requested_presence = dbus.Struct((dbus.UInt32(2L), dbus.String(u'brb'), @@ -108,7 +108,7 @@ def test(q, bus, mc): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) # Assert that the NormalizedName is harvested from the Connection at some # point @@ -129,7 +129,7 @@ def test(q, bus, mc): # Since this Connection doesn't support SimplePresence, but it's online, # the spec says that CurrentPresence should be Unset. - assertEquals((cs.PRESENCE_TYPE_UNSET, "", ""), + assertEquals((cs.PRESENCE_UNSET, "", ""), properties.get('CurrentPresence')) new_channel = http_fixed_properties @@ -146,7 +146,7 @@ def test(q, bus, mc): q.dbus_return(e.message, signature='') # Put the account offline - requested_presence = (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '') + requested_presence = (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '') account.Set(cs.ACCOUNT, 'RequestedPresence', requested_presence, dbus_interface=cs.PROPERTIES_IFACE) diff --git a/tests/twisted/account-manager/server-drops-us.py b/tests/twisted/account-manager/server-drops-us.py index b4db423..c218afe 100644 --- a/tests/twisted/account-manager/server-drops-us.py +++ b/tests/twisted/account-manager/server-drops-us.py @@ -48,7 +48,7 @@ def test(q, bus, mc): dbus_interface=cs.PROPERTIES_IFACE) # Set online presence - presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Fixing MC bugs'), signature='uss') call_async(q, account, 'Set', cs.ACCOUNT, 'RequestedPresence', presence, @@ -72,7 +72,7 @@ def test(q, bus, mc): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) conn = drop_and_expect_reconnect(q, bus, conn) conn = drop_and_expect_reconnect(q, bus, conn) @@ -83,7 +83,7 @@ def test(q, bus, mc): # Connection falls over for a miscellaneous reason conn.StatusChanged(cs.CONN_STATUS_DISCONNECTED, - cs.CONN_STATUS_REASON_NETWORK_ERROR) + cs.CSR_NETWORK_ERROR) # Right, that's it, I'm giving up... # This test can be considered to have succeeded if we don't @@ -98,7 +98,7 @@ def test(q, bus, mc): def drop_and_expect_reconnect(q, bus, conn): # Connection falls over for a miscellaneous reason conn.StatusChanged(cs.CONN_STATUS_DISCONNECTED, - cs.CONN_STATUS_REASON_NETWORK_ERROR) + cs.CSR_NETWORK_ERROR) # MC reconnects @@ -120,7 +120,7 @@ def drop_and_expect_reconnect(q, bus, conn): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) return conn diff --git a/tests/twisted/account-manager/update-parameters.py b/tests/twisted/account-manager/update-parameters.py index a7ec6a0..7bc4e47 100644 --- a/tests/twisted/account-manager/update-parameters.py +++ b/tests/twisted/account-manager/update-parameters.py @@ -83,7 +83,7 @@ def test(q, bus, mc, **kwargs): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) # Assert that the NormalizedName is harvested from the Connection at some # point diff --git a/tests/twisted/capabilities/contact-caps.py b/tests/twisted/capabilities/contact-caps.py index 7a348df..3184c86 100644 --- a/tests/twisted/capabilities/contact-caps.py +++ b/tests/twisted/capabilities/contact-caps.py @@ -56,7 +56,7 @@ def test(q, bus, mc): }, signature='sv') media_fixed_properties = dbus.Dictionary({ - cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_STREAMED_MEDIA, + cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_CALL, }, signature='sv') media_call = SimulatedClient(q, bus, 'MediaCall', observe=[], approve=[], handle=[media_fixed_properties], diff --git a/tests/twisted/constants.py b/tests/twisted/constants.py index 0b359ff..9976110 100644 --- a/tests/twisted/constants.py +++ b/tests/twisted/constants.py @@ -1,5 +1,5 @@ # Copyright (C) 2009 Nokia Corporation -# Copyright (C) 2009-2012 Collabora Ltd. +# Copyright (C) 2009-2013 Collabora Ltd. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,31 +21,59 @@ Some handy constants for other tests to share and enjoy. """ from dbus import PROPERTIES_IFACE, INTROSPECTABLE_IFACE -from servicetest import tp_name_prefix, tp_path_prefix -CM = "org.freedesktop.Telepathy.ConnectionManager" +PREFIX = "org.freedesktop.Telepathy" +PATH_PREFIX = '/' + PREFIX.replace('.', '/') -DBUS_ERROR_NO_REPLY = 'org.freedesktop.DBus.Error.NoReply' +tp_name_prefix = PREFIX +tp_path_prefix = PATH_PREFIX + +CM = PREFIX + ".ConnectionManager" +HT_NONE = 0 HT_CONTACT = 1 HT_ROOM = 2 +HT_LIST = 3 +HT_GROUP = 4 + +CHANNEL = PREFIX + ".Channel" -CHANNEL = tp_name_prefix + ".Channel" +CHANNEL_IFACE_CALL_STATE = CHANNEL + ".Interface.CallState" +CHANNEL_IFACE_CHAT_STATE = CHANNEL + '.Interface.ChatState' CHANNEL_IFACE_DESTROYABLE = CHANNEL + ".Interface.Destroyable" +CHANNEL_IFACE_DTMF = CHANNEL + ".Interface.DTMF" CHANNEL_IFACE_GROUP = CHANNEL + ".Interface.Group" CHANNEL_IFACE_HOLD = CHANNEL + ".Interface.Hold" CHANNEL_IFACE_MEDIA_SIGNALLING = CHANNEL + ".Interface.MediaSignalling" +CHANNEL_IFACE_MESSAGES = CHANNEL + ".Interface.Messages" +CHANNEL_IFACE_PASSWORD = CHANNEL + ".Interface.Password" +CHANNEL_IFACE_TUBE = CHANNEL + ".Interface.Tube" +CHANNEL_IFACE_SASL_AUTH = CHANNEL + ".Interface.SASLAuthentication" +CHANNEL_IFACE_CONFERENCE = CHANNEL + '.Interface.Conference' +CHANNEL_IFACE_ROOM = CHANNEL + '.Interface.Room2' +CHANNEL_IFACE_ROOM_CONFIG = CHANNEL + '.Interface.RoomConfig1' +CHANNEL_IFACE_SUBJECT = CHANNEL + '.Interface.Subject2' +CHANNEL_IFACE_FILE_TRANSFER_METADATA = CHANNEL + '.Interface.FileTransfer.Metadata' + +CHANNEL_TYPE_CALL = CHANNEL + ".Type.Call1" +CHANNEL_TYPE_CONTACT_LIST = CHANNEL + ".Type.ContactList" +CHANNEL_TYPE_CONTACT_SEARCH = CHANNEL + ".Type.ContactSearch" CHANNEL_TYPE_TEXT = CHANNEL + ".Type.Text" CHANNEL_TYPE_TUBES = CHANNEL + ".Type.Tubes" -CHANNEL_IFACE_TUBE = CHANNEL + ".Interface.Tube" CHANNEL_TYPE_STREAM_TUBE = CHANNEL + ".Type.StreamTube" CHANNEL_TYPE_DBUS_TUBE = CHANNEL + ".Type.DBusTube" -CHANNEL_TYPE_STREAMED_MEDIA = CHANNEL + ".Type.StreamedMedia" CHANNEL_TYPE_TEXT = CHANNEL + ".Type.Text" - -TP_AWKWARD_PROPERTIES = tp_name_prefix + ".Properties" +CHANNEL_TYPE_FILE_TRANSFER = CHANNEL + ".Type.FileTransfer" +CHANNEL_TYPE_ROOM_LIST = CHANNEL + ".Type.RoomList" +CHANNEL_TYPE_SERVER_AUTHENTICATION = \ + CHANNEL + ".Type.ServerAuthentication" +CHANNEL_TYPE_SERVER_TLS_CONNECTION = \ + CHANNEL + ".Type.ServerTLSConnection" + +TP_AWKWARD_PROPERTIES = PREFIX + ".Properties" PROPERTY_FLAG_READ = 1 PROPERTY_FLAG_WRITE = 2 +PROPERTY_FLAGS_RW = PROPERTY_FLAG_READ | PROPERTY_FLAG_WRITE CHANNEL_TYPE = CHANNEL + '.ChannelType' TARGET_HANDLE_TYPE = CHANNEL + '.TargetHandleType' @@ -56,64 +84,188 @@ INITIATOR_HANDLE = CHANNEL + '.InitiatorHandle' INITIATOR_ID = CHANNEL + '.InitiatorID' INTERFACES = CHANNEL + '.Interfaces' -CONN = tp_name_prefix + ".Connection" -CONN_IFACE_ALIASING = CONN + '.Interface.Aliasing' +CALL_INITIAL_AUDIO = CHANNEL_TYPE_CALL + '.InitialAudio' +CALL_INITIAL_AUDIO_NAME = CHANNEL_TYPE_CALL + '.InitialAudioName' +CALL_INITIAL_VIDEO = CHANNEL_TYPE_CALL + '.InitialVideo' +CALL_INITIAL_VIDEO_NAME = CHANNEL_TYPE_CALL + '.InitialVideoName' +CALL_MUTABLE_CONTENTS = CHANNEL_TYPE_CALL + '.MutableContents' + +CALL_CONTENT = PREFIX + '.Call1.Content' +CALL_CONTENT_IFACE_MEDIA = CALL_CONTENT + '.Interface.Media' +CALL_CONTENT_IFACE_DTMF = CALL_CONTENT + '.Interface.DTMF' + +CALL_CONTENT_MEDIADESCRIPTION = CALL_CONTENT + '.MediaDescription' + +CALL_STREAM = PREFIX + '.Call1.Stream' +CALL_STREAM_IFACE_MEDIA = CALL_STREAM + '.Interface.Media' + +CALL_STREAM_ENDPOINT = CALL_STREAM + '.Endpoint' + +CALL_MEDIA_TYPE_AUDIO = 0 +CALL_MEDIA_TYPE_VIDEO = 1 + +CALL_CONTENT_PACKETIZATION_RTP = 0 +CALL_CONTENT_PACKETIZATION_RAW = 1 +CALL_CONTENT_PACKETIZATION_MSN_WEBCAM = 2 + +CALL_STREAM_TRANSPORT_UNKNOWN = 0 +CALL_STREAM_TRANSPORT_RAW_UDP = 1 +CALL_STREAM_TRANSPORT_ICE = 2 +CALL_STREAM_TRANSPORT_GTALK_P2P = 3 +CALL_STREAM_TRANSPORT_WLM_2009 = 4 +CALL_STREAM_TRANSPORT_SHM = 5 +CALL_STREAM_TRANSPORT_MULTICAST = 6 + +CALL_STATE_UNKNOWN = 0 +CALL_STATE_PENDING_INITIATOR = 1 +CALL_STATE_INITIALISING = 2 +CALL_STATE_INITIALISED = 3 +CALL_STATE_ACCEPTED = 4 +CALL_STATE_ACTIVE = 5 +CALL_STATE_ENDED = 6 + +CALL_FLAG_LOCALLY_HELD = 1 +CALL_FLAG_LOCALLY_RINGING = 2 +CALL_FLAG_LOCALLY_QUEUED = 4 +CALL_FLAG_FORWARDED = 8 +CALL_FLAG_CLEARING = 16 + +CALL_MEMBER_FLAG_RINGING = 1 +CALL_MEMBER_FLAG_HELD = 2 + +CALL_DISPOSITION_NONE = 0 +CALL_DISPOSITION_INITIAL = 1 + +CALL_SENDING_STATE_NONE = 0 +CALL_SENDING_STATE_PENDING_SEND = 1 +CALL_SENDING_STATE_SENDING = 2 +CALL_SENDING_STATE_PENDING_STOP_SENDING = 3 + +CALL_STREAM_FLOW_STATE_STOPPED = 0 +CALL_STREAM_FLOW_STATE_PENDING_START = 1 +CALL_STREAM_FLOW_STATE_PENDING_STOP = 2 +CALL_STREAM_FLOW_STATE_STARTED = 3 + +CALL_STREAM_ENDPOINT_STATE_CONNECTING = 0 +CALL_STREAM_ENDPOINT_STATE_PROVISIONALLY_CONNECTED = 1 +CALL_STREAM_ENDPOINT_STATE_FULLY_CONNECTED = 2 +CALL_STREAM_ENDPOINT_STATE_EXHAUSTED_CANDIDATES = 3 +CALL_STREAM_ENDPOINT_STATE_FAILED = 4 + +CALL_STREAM_CANDIDATE_TYPE_HOST = 1 +CALL_STREAM_CANDIDATE_TYPE_SERVER_REFLEXIVE = 2 +CALL_STREAM_CANDIDATE_TYPE_RELAY = 4 + +CALL_STATE_CHANGE_REASON_UNKNOWN = 0 +CALL_STATE_CHANGE_REASON_PROGRESS_MADE = 1 +CALL_STATE_CHANGE_REASON_USER_REQUESTED = 2 +CALL_STATE_CHANGE_REASON_FORWARDED = 3 +CALL_STATE_CHANGE_REASON_REJECTED = 4 +CALL_STATE_CHANGE_REASON_NO_ANSWER = 5 +CALL_STATE_CHANGE_REASON_INVALID_CONTACT = 6 +CALL_STATE_CHANGE_REASON_PERMISSION_DENIED = 7 +CALL_STATE_CHANGE_REASON_BUSY = 8 +CALL_STATE_CHANGE_REASON_INTERNAL_ERROR = 9 +CALL_STATE_CHANGE_REASON_SERVICE_ERROR = 10 +CALL_STATE_CHANGE_REASON_NETWORK_ERROR = 11 +CALL_STATE_CHANGE_REASON_MEDIA_ERROR = 12 +CALL_STATE_CHANGE_REASON_CONNECTIVITY_ERROR = 13 + +CALL_STREAM_COMPONENT_UNKNOWN = 0 +CALL_STREAM_COMPONENT_DATA = 1 +CALL_STREAM_COMPONENT_CONTROL = 2 + +SUBSCRIPTION_STATE_UNKNOWN = 0 +SUBSCRIPTION_STATE_NO = 1 +SUBSCRIPTION_STATE_REMOVED_REMOTELY = 2 +SUBSCRIPTION_STATE_ASK = 3 +SUBSCRIPTION_STATE_YES = 4 + +CONTACT_LIST_STATE_NONE = 0 +CONTACT_LIST_STATE_WAITING = 1 +CONTACT_LIST_STATE_FAILURE = 2 +CONTACT_LIST_STATE_SUCCESS = 3 + +CONN = PREFIX + ".Connection" CONN_IFACE_AVATARS = CONN + '.Interface.Avatars' +CONN_IFACE_ALIASING = CONN + '.Interface.Aliasing' CONN_IFACE_CAPS = CONN + '.Interface.Capabilities' CONN_IFACE_CONTACTS = CONN + '.Interface.Contacts' CONN_IFACE_CONTACT_CAPS = CONN + '.Interface.ContactCapabilities' -CONN_IFACE_REQUESTS = CONN + '.Interface.Requests' +CONN_IFACE_CONTACT_INFO = CONN + ".Interface.ContactInfo" +CONN_IFACE_PRESENCE = CONN + '.Interface.Presence' CONN_IFACE_SIMPLE_PRESENCE = CONN + '.Interface.SimplePresence' +CONN_IFACE_REQUESTS = CONN + '.Interface.Requests' +CONN_IFACE_LOCATION = CONN + '.Interface.Location' +CONN_IFACE_GABBLE_DECLOAK = CONN + '.Interface.Gabble.Decloak' +CONN_IFACE_MAIL_NOTIFICATION = CONN + '.Interface.MailNotification' +CONN_IFACE_CONTACT_LIST = CONN + '.Interface.ContactList' +CONN_IFACE_CONTACT_GROUPS = CONN + '.Interface.ContactGroups' +CONN_IFACE_CLIENT_TYPES = CONN + '.Interface.ClientTypes' CONN_IFACE_POWER_SAVING = CONN + '.Interface.PowerSaving' +CONN_IFACE_CONTACT_BLOCKING = CONN + '.Interface.ContactBlocking' +CONN_IFACE_ADDRESSING = CONN + '.Interface.Addressing1' CONN_IFACE_SERVICE_POINT = CONN + '.Interface.ServicePoint' -CONN_STATUS_CONNECTED = 0 -CONN_STATUS_CONNECTING = 1 -CONN_STATUS_DISCONNECTED = 2 +ATTR_CONTACT_ID = CONN + '/contact-id' +ATTR_CONTACT_CAPABILITIES = CONN_IFACE_CONTACT_CAPS + '/capabilities' +ATTR_PRESENCE = CONN_IFACE_SIMPLE_PRESENCE + '/presence' +ATTR_SUBSCRIBE = CONN_IFACE_CONTACT_LIST + '/subscribe' +ATTR_PUBLISH = CONN_IFACE_CONTACT_LIST + '/publish' +ATTR_GROUPS = CONN_IFACE_CONTACT_GROUPS + '/groups' -CONN_STATUS_REASON_NONE = 0 -CONN_STATUS_REASON_REQUESTED = 1 -CONN_STATUS_REASON_NETWORK_ERROR = 2 - -GROUP_REASON_NONE = 0 -GROUP_REASON_OFFLINE = 1 -GROUP_REASON_KICKED = 2 -GROUP_REASON_BUSY = 3 -GROUP_REASON_INVITED = 4 -GROUP_REASON_BANNED = 5 -GROUP_REASON_ERROR = 6 -GROUP_REASON_INVALID_CONTACT = 7 -GROUP_REASON_NO_ANSWER = 8 -GROUP_REASON_RENAMED = 9 -GROUP_REASON_PERMISSION_DENIED = 10 -GROUP_REASON_SEPARATED = 11 - -PRESENCE_TYPE_UNSET = 0 -PRESENCE_TYPE_OFFLINE = 1 -PRESENCE_TYPE_AVAILABLE = 2 -PRESENCE_TYPE_AWAY = 3 -PRESENCE_TYPE_XA = 4 -PRESENCE_TYPE_HIDDEN = 5 -PRESENCE_TYPE_BUSY = 6 -PRESENCE_TYPE_UNKNOWN = 7 -PRESENCE_TYPE_ERROR = 8 - -ERROR = tp_name_prefix + '.Error' +STREAM_HANDLER = PREFIX + '.Media.StreamHandler' + +ERROR = PREFIX + '.Error' INVALID_ARGUMENT = ERROR + '.InvalidArgument' -INVALID_HANDLE = ERROR + '.InvalidHandle' NOT_IMPLEMENTED = ERROR + '.NotImplemented' NOT_AVAILABLE = ERROR + '.NotAvailable' PERMISSION_DENIED = ERROR + '.PermissionDenied' +OFFLINE = ERROR + '.Offline' +NOT_CAPABLE = ERROR + '.NotCapable' +CONNECTION_REFUSED = ERROR + '.ConnectionRefused' +CONNECTION_FAILED = ERROR + '.ConnectionFailed' +CONNECTION_LOST = ERROR + '.ConnectionLost' CANCELLED = ERROR + '.Cancelled' NOT_YOURS = ERROR + '.NotYours' DISCONNECTED = ERROR + '.Disconnected' -NOT_CAPABLE = ERROR + '.NotCapable' +REGISTRATION_EXISTS = ERROR + '.RegistrationExists' +AUTHENTICATION_FAILED = ERROR + '.AuthenticationFailed' +CONNECTION_REPLACED = ERROR + '.ConnectionReplaced' +ALREADY_CONNECTED = ERROR + '.AlreadyConnected' +NETWORK_ERROR = ERROR + '.NetworkError' +NOT_YET = ERROR + '.NotYet' +INVALID_HANDLE = ERROR + '.InvalidHandle' +CERT_UNTRUSTED = ERROR + '.Cert.Untrusted' +SERVICE_BUSY = ERROR + '.ServiceBusy' +SERVICE_CONFUSED = ERROR + '.ServiceConfused' + +BANNED = ERROR + '.Channel.Banned' + +DBUS_ERROR_UNKNOWN_METHOD = 'org.freedesktop.DBus.Error.UnknownMethod' +DBUS_ERROR_NO_REPLY = 'org.freedesktop.DBus.Error.NoReply' TUBE_PARAMETERS = CHANNEL_IFACE_TUBE + '.Parameters' TUBE_STATE = CHANNEL_IFACE_TUBE + '.State' STREAM_TUBE_SERVICE = CHANNEL_TYPE_STREAM_TUBE + '.Service' DBUS_TUBE_SERVICE_NAME = CHANNEL_TYPE_DBUS_TUBE + '.ServiceName' DBUS_TUBE_DBUS_NAMES = CHANNEL_TYPE_DBUS_TUBE + '.DBusNames' +DBUS_TUBE_SUPPORTED_ACCESS_CONTROLS = CHANNEL_TYPE_DBUS_TUBE + '.SupportedAccessControls' +STREAM_TUBE_SUPPORTED_SOCKET_TYPES = CHANNEL_TYPE_STREAM_TUBE + '.SupportedSocketTypes' + +CONFERENCE_INITIAL_CHANNELS = CHANNEL_IFACE_CONFERENCE + '.InitialChannels' +CONFERENCE_INITIAL_INVITEE_HANDLES = CHANNEL_IFACE_CONFERENCE + '.InitialInviteeHandles' +CONFERENCE_INITIAL_INVITEE_IDS = CHANNEL_IFACE_CONFERENCE + '.InitialInviteeIDs' + +CONTACT_SEARCH_ASK = CHANNEL_TYPE_CONTACT_SEARCH + '.AvailableSearchKeys' +CONTACT_SEARCH_SERVER = CHANNEL_TYPE_CONTACT_SEARCH + '.Server' +CONTACT_SEARCH_STATE = CHANNEL_TYPE_CONTACT_SEARCH + '.SearchState' + +SEARCH_NOT_STARTED = 0 +SEARCH_IN_PROGRESS = 1 +SEARCH_MORE_AVAILABLE = 2 +SEARCH_COMPLETED = 3 +SEARCH_FAILED = 4 TUBE_CHANNEL_STATE_LOCAL_PENDING = 0 TUBE_CHANNEL_STATE_REMOTE_PENDING = 1 @@ -123,6 +275,13 @@ TUBE_CHANNEL_STATE_NOT_OFFERED = 3 MEDIA_STREAM_TYPE_AUDIO = 0 MEDIA_STREAM_TYPE_VIDEO = 1 +MEDIA_STREAM_BASE_PROTO_UDP = 0 +MEDIA_STREAM_BASE_PROTO_TCP = 1 + +MEDIA_STREAM_TRANSPORT_TYPE_LOCAL = 0 +MEDIA_STREAM_TRANSPORT_TYPE_DERIVED = 1 +MEDIA_STREAM_TRANSPORT_TYPE_RELAY = 2 + SOCKET_ADDRESS_TYPE_UNIX = 0 SOCKET_ADDRESS_TYPE_ABSTRACT_UNIX = 1 SOCKET_ADDRESS_TYPE_IPV4 = 2 @@ -161,41 +320,286 @@ MEDIA_STREAM_DIRECTION_SEND = 1 MEDIA_STREAM_DIRECTION_RECEIVE = 2 MEDIA_STREAM_DIRECTION_BIDIRECTIONAL = 3 +FT_STATE_NONE = 0 +FT_STATE_PENDING = 1 +FT_STATE_ACCEPTED = 2 +FT_STATE_OPEN = 3 +FT_STATE_COMPLETED = 4 +FT_STATE_CANCELLED = 5 + +FT_STATE_CHANGE_REASON_NONE = 0 +FT_STATE_CHANGE_REASON_REQUESTED = 1 +FT_STATE_CHANGE_REASON_LOCAL_STOPPED = 2 +FT_STATE_CHANGE_REASON_REMOTE_STOPPED = 3 +FT_STATE_CHANGE_REASON_LOCAL_ERROR = 4 +FT_STATE_CHANGE_REASON_REMOTE_ERROR = 5 + +FILE_HASH_TYPE_NONE = 0 +FILE_HASH_TYPE_MD5 = 1 +FILE_HASH_TYPE_SHA1 = 2 +FILE_HASH_TYPE_SHA256 = 3 + +FT_STATE = CHANNEL_TYPE_FILE_TRANSFER + '.State' +FT_CONTENT_TYPE = CHANNEL_TYPE_FILE_TRANSFER + '.ContentType' +FT_FILENAME = CHANNEL_TYPE_FILE_TRANSFER + '.Filename' +FT_SIZE = CHANNEL_TYPE_FILE_TRANSFER + '.Size' +FT_CONTENT_HASH_TYPE = CHANNEL_TYPE_FILE_TRANSFER + '.ContentHashType' +FT_CONTENT_HASH = CHANNEL_TYPE_FILE_TRANSFER + '.ContentHash' +FT_DESCRIPTION = CHANNEL_TYPE_FILE_TRANSFER + '.Description' +FT_DATE = CHANNEL_TYPE_FILE_TRANSFER + '.Date' +FT_AVAILABLE_SOCKET_TYPES = CHANNEL_TYPE_FILE_TRANSFER + '.AvailableSocketTypes' +FT_TRANSFERRED_BYTES = CHANNEL_TYPE_FILE_TRANSFER + '.TransferredBytes' +FT_INITIAL_OFFSET = CHANNEL_TYPE_FILE_TRANSFER + '.InitialOffset' +FT_FILE_COLLECTION = CHANNEL_TYPE_FILE_TRANSFER + '.FUTURE.FileCollection' +FT_URI = CHANNEL_TYPE_FILE_TRANSFER + '.URI' +FT_SERVICE_NAME = CHANNEL_IFACE_FILE_TRANSFER_METADATA + '.ServiceName' +FT_METADATA = CHANNEL_IFACE_FILE_TRANSFER_METADATA + '.Metadata' + +GF_CAN_ADD = 1 +GF_CAN_REMOVE = 2 +GF_CAN_RESCIND = 4 +GF_MESSAGE_ADD = 8 +GF_MESSAGE_REMOVE = 16 +GF_MESSAGE_ACCEPT = 32 +GF_MESSAGE_REJECT = 64 +GF_MESSAGE_RESCIND = 128 +GF_CHANNEL_SPECIFIC_HANDLES = 256 +GF_ONLY_ONE_GROUP = 512 +GF_HANDLE_OWNERS_NOT_AVAILABLE = 1024 +GF_PROPERTIES = 2048 +GF_MEMBERS_CHANGED_DETAILED = 4096 + +GC_REASON_NONE = 0 +GC_REASON_OFFLINE = 1 +GC_REASON_KICKED = 2 +GC_REASON_BUSY = 3 +GC_REASON_INVITED = 4 +GC_REASON_BANNED = 5 +GC_REASON_ERROR = 6 +GC_REASON_INVALID_CONTACT = 7 +GC_REASON_NO_ANSWER = 8 +GC_REASON_RENAMED = 9 +GC_REASON_PERMISSION_DENIED = 10 +GC_REASON_SEPARATED = 11 + +HS_UNHELD = 0 +HS_HELD = 1 +HS_PENDING_HOLD = 2 +HS_PENDING_UNHOLD = 3 + +HSR_NONE = 0 +HSR_REQUESTED = 1 +HSR_RESOURCE_NOT_AVAILABLE = 2 + +CONN_STATUS_CONNECTED = 0 +CONN_STATUS_CONNECTING = 1 +CONN_STATUS_DISCONNECTED = 2 + +CSR_NONE_SPECIFIED = 0 +CSR_REQUESTED = 1 +CSR_NETWORK_ERROR = 2 +CSR_AUTHENTICATION_FAILED = 3 +CSR_ENCRYPTION_ERROR = 4 +CSR_NAME_IN_USE = 5 +CSR_CERT_NOT_PROVIDED = 6 +CSR_CERT_UNTRUSTED = 7 +CSR_CERT_EXPIRED = 8 +CSR_CERT_NOT_ACTIVATED = 9 +CSR_CERT_HOSTNAME_MISMATCH = 10 +CSR_CERT_FINGERPRINT_MISMATCH = 11 +CSR_CERT_SELF_SIGNED = 12 +CSR_CERT_OTHER_ERROR = 13 + +BUDDY_INFO = 'org.laptop.Telepathy.BuddyInfo' +ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties' + +CHAT_STATE_GONE = 0 +CHAT_STATE_INACTIVE = 1 +CHAT_STATE_ACTIVE = 2 +CHAT_STATE_PAUSED = 3 +CHAT_STATE_COMPOSING = 4 + +# Channel_Media_Capabilities +MEDIA_CAP_AUDIO = 1 +MEDIA_CAP_VIDEO = 2 +MEDIA_CAP_STUN = 4 +MEDIA_CAP_GTALKP2P = 8 +MEDIA_CAP_ICEUDP = 16 +MEDIA_CAP_IMMUTABLE_STREAMS = 32 + +CLIENT = PREFIX + '.Client' + +PRESENCE_UNSET = 0 +PRESENCE_OFFLINE = 1 +PRESENCE_AVAILABLE = 2 +PRESENCE_AWAY = 3 +PRESENCE_EXTENDED_AWAY = 4 +PRESENCE_HIDDEN = 5 +PRESENCE_BUSY = 6 +PRESENCE_UNKNOWN = 7 +PRESENCE_ERROR = 8 + +CONTACT_INFO_FLAG_CAN_SET = 1 +CONTACT_INFO_FLAG_PUSH = 2 +CONTACT_INFO_FIELD_FLAG_PARAMETERS_EXACT = 1 +CONTACT_INFO_FIELD_FLAG_OVERWRITTEN_BY_NICKNAME = 2 + +# Channel_Interface_SaslAuthentication +SASL_STATUS_NOT_STARTED = 0 +SASL_STATUS_IN_PROGRESS = 1 +SASL_STATUS_SERVER_SUCCEEDED = 2 +SASL_STATUS_CLIENT_ACCEPTED = 3 +SASL_STATUS_SUCCEEDED = 4 +SASL_STATUS_SERVER_FAILED = 5 +SASL_STATUS_CLIENT_FAILED = 6 + +SASL_ABORT_REASON_INVALID_CHALLENGE = 0 +SASL_ABORT_REASON_USER_ABORT = 1 + +AUTH_METHOD = CHANNEL_TYPE_SERVER_AUTHENTICATION + ".AuthenticationMethod" +SASL_AVAILABLE_MECHANISMS = CHANNEL_IFACE_SASL_AUTH + ".AvailableMechanisms" +SASL_STATUS = CHANNEL_IFACE_SASL_AUTH + ".SASLStatus" +SASL_ERROR = CHANNEL_IFACE_SASL_AUTH + ".SASLError" +SASL_ERROR_DETAILS = CHANNEL_IFACE_SASL_AUTH + ".SASLErrorDetails" +SASL_CONTEXT = CHANNEL_IFACE_SASL_AUTH + ".SASLContext" +SASL_AUTHORIZATION_IDENTITY = CHANNEL_IFACE_SASL_AUTH + ".AuthorizationIdentity" +SASL_DEFAULT_REALM = CHANNEL_IFACE_SASL_AUTH + ".DefaultRealm" +SASL_DEFAULT_USERNAME = CHANNEL_IFACE_SASL_AUTH + ".DefaultUsername" + +# Channel_Type_ServerTLSConnection +TLS_CERT_PATH = CHANNEL_TYPE_SERVER_TLS_CONNECTION + ".ServerCertificate" +TLS_HOSTNAME = CHANNEL_TYPE_SERVER_TLS_CONNECTION + ".Hostname" +TLS_REFERENCE_IDENTITIES = \ + CHANNEL_TYPE_SERVER_TLS_CONNECTION + ".ReferenceIdentities" + +# Connection.Interface.Location + +LOCATION_FEATURE_CAN_SET = 1 + +# Channel.Type.Text + +MT_NORMAL = 0 +MT_ACTION = 1 +MT_NOTICE = 2 +MT_AUTO_REPLY = 3 +MT_DELIVERY_REPORT = 4 + +class MessageFlag(object): + TRUNCATED = 1 + NON_TEXT_CONTENT = 2 + SCROLLBACK = 4 + RESCUED = 8 + +class SendError(object): + UNKNOWN = 0 + OFFLINE = 1 + INVALID_CONTACT = 2 + PERMISSION_DENIED = 3 + TOO_LONG = 4 + NOT_IMPLEMENTED = 5 + +PROTOCOL = PREFIX + '.Protocol' +PROTOCOL_IFACE_PRESENCES = PROTOCOL + '.Interface.Presence' +PROTOCOL_IFACE_ADDRESSING = PROTOCOL + '.Interface.Addressing' +PROTOCOL_IFACE_AVATARS = PROTOCOL + '.Interface.Avatars' + +PARAM_REQUIRED = 1 +PARAM_REGISTER = 2 +PARAM_HAS_DEFAULT = 4 +PARAM_SECRET = 8 +PARAM_DBUS_PROPERTY = 16 + +AUTHENTICATION = PREFIX + '.Authentication' +AUTH_TLS_CERT = AUTHENTICATION + ".TLSCertificate" + +TLS_CERT_STATE_PENDING = 0 +TLS_CERT_STATE_ACCEPTED = 1 +TLS_CERT_STATE_REJECTED = 2 + +TLS_REJECT_REASON_UNKNOWN = 0 +TLS_REJECT_REASON_UNTRUSTED = 1 + +# Channel.Interface.Messages + +MESSAGE_PART_SUPPORT_FLAGS = CHANNEL_IFACE_MESSAGES + '.MessagePartSupportFlags' +DELIVERY_REPORTING_SUPPORT = CHANNEL_IFACE_MESSAGES + '.DeliveryReportingSupport' +SUPPORTED_CONTENT_TYPES = CHANNEL_IFACE_MESSAGES + '.SupportedContentTypes' + +MSG_SENDING_FLAGS_REPORT_DELIVERY = 1 +MSG_SENDING_FLAGS_REPORT_READ = 2 +MSG_SENDING_FLAGS_REPORT_DELETED = 4 + +DELIVERY_REPORTING_SUPPORT_FLAGS_RECEIVE_FAILURES = 1 +DELIVERY_REPORTING_SUPPORT_FLAGS_RECEIVE_SUCCESSES = 2 +DELIVERY_REPORTING_SUPPORT_FLAGS_RECEIVE_READ = 4 +DELIVERY_REPORTING_SUPPORT_FLAGS_RECEIVE_DELETED = 8 + +DELIVERY_STATUS_UNKNOWN = 0 +DELIVERY_STATUS_DELIVERED = 1 +DELIVERY_STATUS_TEMPORARILY_FAILED = 2 +DELIVERY_STATUS_PERMANENTLY_FAILED = 3 +DELIVERY_STATUS_ACCEPTED = 4 +DELIVERY_STATUS_READ = 5 +DELIVERY_STATUS_DELETED = 6 + +MEDIA_STREAM_ERROR_UNKNOWN = 0 +MEDIA_STREAM_ERROR_EOS = 1 +MEDIA_STREAM_ERROR_CODEC_NEGOTIATION_FAILED = 2 +MEDIA_STREAM_ERROR_CONNECTION_FAILED = 3 +MEDIA_STREAM_ERROR_NETWORK_ERROR = 4 +MEDIA_STREAM_ERROR_NO_CODECS = 5 +MEDIA_STREAM_ERROR_INVALID_CM_BEHAVIOR = 6 +MEDIA_STREAM_ERROR_MEDIA_ERROR = 7 + +PASSWORD_FLAG_PROVIDE = 8 + +# Channel.Interface.Room +ROOM_NAME = CHANNEL_IFACE_ROOM + '.RoomName' +ROOM_SERVER = CHANNEL_IFACE_ROOM + '.Server' + +# Channel.Interface.Subject +SUBJECT = CHANNEL_IFACE_ROOM + '.Subject' +SUBJECT_PRESENT = 1 +SUBJECT_CAN_SET = 2 + +DEBUG_IFACE = PREFIX + '.Debug' +DEBUG_PATH = PATH_PREFIX + '/debug' + SERVICE_POINT_TYPE_NONE = 0 SERVICE_POINT_TYPE_EMERGENCY = 1 SERVICE_POINT_TYPE_COUNSELING = 2 -CLIENT = tp_name_prefix + '.Client' -CLIENT_PATH = tp_path_prefix + '/Client' -OBSERVER = tp_name_prefix + '.Client.Observer' -APPROVER = tp_name_prefix + '.Client.Approver' -HANDLER = tp_name_prefix + '.Client.Handler' +CLIENT = PREFIX + '.Client' +CLIENT_PATH = PATH_PREFIX + '/Client' +OBSERVER = PREFIX + '.Client.Observer' +APPROVER = PREFIX + '.Client.Approver' +HANDLER = PREFIX + '.Client.Handler' CLIENT_IFACE_REQUESTS = CLIENT + '.Interface.Requests' -ACCOUNT = tp_name_prefix + '.Account' +ACCOUNT = PREFIX + '.Account' ACCOUNT_IFACE_AVATAR = ACCOUNT + '.Interface.Avatar' ACCOUNT_IFACE_ADDRESSING = ACCOUNT + '.Interface.Addressing' ACCOUNT_IFACE_HIDDEN = ACCOUNT + '.Interface.Hidden.DRAFT1' ACCOUNT_IFACE_NOKIA_CONDITIONS = 'com.nokia.Account.Interface.Conditions' -ACCOUNT_PATH_PREFIX = tp_path_prefix + '/Account/' +ACCOUNT_PATH_PREFIX = PATH_PREFIX + '/Account/' -AM = tp_name_prefix + '.AccountManager' +AM = PREFIX + '.AccountManager' AM_IFACE_HIDDEN = AM + '.Interface.Hidden.DRAFT1' -AM_PATH = tp_path_prefix + '/AccountManager' +AM_PATH = PATH_PREFIX + '/AccountManager' -CR = tp_name_prefix + '.ChannelRequest' -CDO = tp_name_prefix + '.ChannelDispatchOperation' +CR = PREFIX + '.ChannelRequest' +CDO = PREFIX + '.ChannelDispatchOperation' -CD = tp_name_prefix + '.ChannelDispatcher' -CD_IFACE_OP_LIST = tp_name_prefix + '.ChannelDispatcher.Interface.OperationList' -CD_PATH = tp_path_prefix + '/ChannelDispatcher' +CD = PREFIX + '.ChannelDispatcher' +CD_IFACE_OP_LIST = PREFIX + '.ChannelDispatcher.Interface.OperationList' +CD_PATH = PATH_PREFIX + '/ChannelDispatcher' CD_REDISPATCH = CD + '.Interface.Redispatch.DRAFT' -MC = tp_name_prefix + '.MissionControl5' -MC_PATH = tp_path_prefix + '/MissionControl5' +MC = PREFIX + '.MissionControl5' +MC_PATH = PATH_PREFIX + '/MissionControl5' -TESTDOT = "org.freedesktop.Telepathy.MC.Test." -TESTSLASH = "/org/freedesktop/Telepathy/MC/Test/" +TESTDOT = PREFIX + ".Test." +TESTSLASH = PATH_PREFIX + "/Test/" TEST_DBUS_ACCOUNT_SERVICE = TESTDOT + "DBusAccountService" TEST_DBUS_ACCOUNT_SERVICE_PATH = TESTSLASH + "DBusAccountService" @@ -203,9 +607,3 @@ TEST_DBUS_ACCOUNT_SERVICE_IFACE = TEST_DBUS_ACCOUNT_SERVICE TEST_DBUS_ACCOUNT_PLUGIN_PATH = TESTSLASH + "DBusAccountPlugin" TEST_DBUS_ACCOUNT_PLUGIN_IFACE = TESTDOT + "DBusAccountPlugin" - -PARAM_FLAG_REQUIRED = 1 -PARAM_FLAG_REGISTER = 2 -PARAM_FLAG_HAS_DEFAULT = 4 -PARAM_FLAG_SECRET = 8 -PARAM_FLAG_DBUS_PROPERTY = 16 diff --git a/tests/twisted/dbus-account-plugin.c b/tests/twisted/dbus-account-plugin.c index 16b1c9c..9d8850e 100644 --- a/tests/twisted/dbus-account-plugin.c +++ b/tests/twisted/dbus-account-plugin.c @@ -25,8 +25,8 @@ #define DEBUG(format, ...) g_debug ("%s: " format, G_STRFUNC, ##__VA_ARGS__) -#define TESTDOT "org.freedesktop.Telepathy.MC.Test." -#define TESTSLASH "/org/freedesktop/Telepathy/MC/Test/" +#define TESTDOT "org.freedesktop.Telepathy.Test." +#define TESTSLASH "/org/freedesktop/Telepathy/Test/" #define TEST_DBUS_ACCOUNT_SERVICE TESTDOT "DBusAccountService" #define TEST_DBUS_ACCOUNT_SERVICE_PATH TESTSLASH "DBusAccountService" diff --git a/tests/twisted/dispatcher/already-has-channel.py b/tests/twisted/dispatcher/already-has-channel.py index 547acdf..b5b0b0c 100644 --- a/tests/twisted/dispatcher/already-has-channel.py +++ b/tests/twisted/dispatcher/already-has-channel.py @@ -83,7 +83,7 @@ def test(q, bus, mc): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) get_interfaces_call = q.expect('dbus-method-call', method='GetInterfaces', path=conn.object_path, handled=False) diff --git a/tests/twisted/dispatcher/already-has-obsolete.py b/tests/twisted/dispatcher/already-has-obsolete.py index 05dcb11..8788169 100644 --- a/tests/twisted/dispatcher/already-has-obsolete.py +++ b/tests/twisted/dispatcher/already-has-obsolete.py @@ -82,7 +82,7 @@ def test(q, bus, mc): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) get_interfaces_call = q.expect('dbus-method-call', method='GetInterfaces', path=conn.object_path, handled=False) diff --git a/tests/twisted/dispatcher/capture-bundle.py b/tests/twisted/dispatcher/capture-bundle.py index de77384..6b75d83 100644 --- a/tests/twisted/dispatcher/capture-bundle.py +++ b/tests/twisted/dispatcher/capture-bundle.py @@ -43,7 +43,7 @@ def test(q, bus, mc): }, signature='sv') voip_fixed_properties = dbus.Dictionary({ cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT, - cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_STREAMED_MEDIA, + cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_CALL, }, signature='sv') # Two clients want to observe, approve and handle text and VoIP channels. diff --git a/tests/twisted/dispatcher/connect-for-request.py b/tests/twisted/dispatcher/connect-for-request.py index 1be141f..e32b520 100644 --- a/tests/twisted/dispatcher/connect-for-request.py +++ b/tests/twisted/dispatcher/connect-for-request.py @@ -38,11 +38,11 @@ def test(q, bus, mc): # automatically call_async(q, account_props, 'Set', cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '')) + (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) q.expect('dbus-return', method='Set') call_async(q, account_props, 'Set', cs.ACCOUNT, 'AutomaticPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Testing automatic presence')) q.expect('dbus-return', method='Set') q.expect('dbus-signal', signal='AccountPropertyChanged', @@ -108,8 +108,8 @@ def test(q, bus, mc): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) - conn.presence = dbus.Struct((cs.PRESENCE_TYPE_AVAILABLE, 'available', ''), + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) + conn.presence = dbus.Struct((cs.PRESENCE_AVAILABLE, 'available', ''), signature='uss') _, cm_request_call = q.expect_many( @@ -123,7 +123,7 @@ def test(q, bus, mc): q.dbus_emit(conn.object_path, cs.CONN_IFACE_SIMPLE_PRESENCE, 'PresencesChanged', - {conn.self_handle: (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + {conn.self_handle: (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Testing automatic presence')}, signature='a{u(uss)}') diff --git a/tests/twisted/dispatcher/create-at-startup.py b/tests/twisted/dispatcher/create-at-startup.py index e0d7372..7537faa 100644 --- a/tests/twisted/dispatcher/create-at-startup.py +++ b/tests/twisted/dispatcher/create-at-startup.py @@ -133,7 +133,7 @@ def test(q, bus, unused, **kwargs): q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) # A channel appears spontaneously diff --git a/tests/twisted/dispatcher/create-text.py b/tests/twisted/dispatcher/create-text.py index 5a0efe1..a09ae98 100644 --- a/tests/twisted/dispatcher/create-text.py +++ b/tests/twisted/dispatcher/create-text.py @@ -71,7 +71,7 @@ def test(q, bus, mc): test_channel_creation(q, bus, account, client, conn, True) test_channel_creation(q, bus, account, client, conn, False, unsuitable) test_channel_creation(q, bus, account, client, conn, False, unsuitable, - cs.CHANNEL_TYPE_STREAMED_MEDIA) + cs.CHANNEL_TYPE_CALL) def test_channel_creation(q, bus, account, client, conn, ensure=False, prefer=None, channel_type=cs.CHANNEL_TYPE_TEXT): diff --git a/tests/twisted/dispatcher/dispatch-before-connected.py b/tests/twisted/dispatcher/dispatch-before-connected.py index 9925e0f..a668c19 100644 --- a/tests/twisted/dispatcher/dispatch-before-connected.py +++ b/tests/twisted/dispatcher/dispatch-before-connected.py @@ -61,7 +61,7 @@ def test(q, bus, mc): expect_client_setup(q, [verifier]) account_props.Set(cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_AVAILABLE), 'available', '')) + (dbus.UInt32(cs.PRESENCE_AVAILABLE), 'available', '')) account_props.Set(cs.ACCOUNT, 'Enabled', True) diff --git a/tests/twisted/dispatcher/exploding-bundles.py b/tests/twisted/dispatcher/exploding-bundles.py index 27d3be3..a8f06c3 100644 --- a/tests/twisted/dispatcher/exploding-bundles.py +++ b/tests/twisted/dispatcher/exploding-bundles.py @@ -43,7 +43,7 @@ def test(q, bus, mc): media_fixed_properties = dbus.Dictionary({ cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT, - cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_STREAMED_MEDIA, + cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_CALL, }, signature='sv') misc_fixed_properties = dbus.Dictionary({ diff --git a/tests/twisted/dispatcher/recover-from-disconnect.py b/tests/twisted/dispatcher/recover-from-disconnect.py index 9ae81e5..87c85d6 100644 --- a/tests/twisted/dispatcher/recover-from-disconnect.py +++ b/tests/twisted/dispatcher/recover-from-disconnect.py @@ -68,7 +68,7 @@ def test(q, bus, mc): dbus_interface=cs.PROPERTIES_IFACE) # Set online presence - presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Fixing MC bugs'), signature='uss') call_async(q, account, 'Set', cs.ACCOUNT, 'RequestedPresence', presence, @@ -99,13 +99,13 @@ def test(q, bus, mc): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) test_dispatching(q, bus, conn, account, empathy, kopete) # Connection falls over for a miscellaneous reason conn.StatusChanged(cs.CONN_STATUS_DISCONNECTED, - cs.CONN_STATUS_REASON_NETWORK_ERROR) + cs.CSR_NETWORK_ERROR) # MC reconnects @@ -134,7 +134,7 @@ def test(q, bus, mc): path=conn.object_path, handled=True) # Connect succeeds - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) test_dispatching(q, bus, conn, account, empathy, kopete) diff --git a/tests/twisted/dispatcher/request-disabled-account.py b/tests/twisted/dispatcher/request-disabled-account.py index 863f054..adb3ca2 100644 --- a/tests/twisted/dispatcher/request-disabled-account.py +++ b/tests/twisted/dispatcher/request-disabled-account.py @@ -35,11 +35,11 @@ def test(q, bus, mc): account_props = dbus.Interface(account, cs.PROPERTIES_IFACE) call_async(q, account_props, 'Set', cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '')) + (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) q.expect('dbus-return', method='Set') call_async(q, account_props, 'Set', cs.ACCOUNT, 'AutomaticPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_BUSY), 'busy', + (dbus.UInt32(cs.PRESENCE_BUSY), 'busy', 'Testing automatic presence')) q.expect('dbus-return', method='Set') q.expect('dbus-signal', signal='AccountPropertyChanged', diff --git a/tests/twisted/mctest.py b/tests/twisted/mctest.py index edd8a24..de75aba 100644 --- a/tests/twisted/mctest.py +++ b/tests/twisted/mctest.py @@ -166,7 +166,7 @@ def exec_test_deferred (fun, params, protocol=None, timeout=None, try: account.Properties.Set(cs.ACCOUNT, 'RequestedPresence', - (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', + (dbus.UInt32(cs.PRESENCE_OFFLINE), 'offline', '')) except dbus.DBusException, e: print >> sys.stderr, "Can't set %s offline: %s" % (a, e) @@ -361,20 +361,20 @@ class SimulatedConnection(object): method='SetAvatar') self.statuses = dbus.Dictionary({ - 'available': (cs.PRESENCE_TYPE_AVAILABLE, True, True), - 'away': (cs.PRESENCE_TYPE_AWAY, True, True), - 'lunch': (cs.PRESENCE_TYPE_XA, True, True), - 'busy': (cs.PRESENCE_TYPE_BUSY, True, True), - 'phone': (cs.PRESENCE_TYPE_BUSY, True, True), - 'offline': (cs.PRESENCE_TYPE_OFFLINE, False, False), - 'error': (cs.PRESENCE_TYPE_ERROR, False, False), - 'unknown': (cs.PRESENCE_TYPE_UNKNOWN, False, False), + 'available': (cs.PRESENCE_AVAILABLE, True, True), + 'away': (cs.PRESENCE_AWAY, True, True), + 'lunch': (cs.PRESENCE_EXTENDED_AWAY, True, True), + 'busy': (cs.PRESENCE_BUSY, True, True), + 'phone': (cs.PRESENCE_BUSY, True, True), + 'offline': (cs.PRESENCE_OFFLINE, False, False), + 'error': (cs.PRESENCE_ERROR, False, False), + 'unknown': (cs.PRESENCE_UNKNOWN, False, False), }, signature='s(ubb)') if has_hidden: - self.statuses['hidden'] = (cs.PRESENCE_TYPE_HIDDEN, True, True) + self.statuses['hidden'] = (cs.PRESENCE_HIDDEN, True, True) - self.presence = dbus.Struct((cs.PRESENCE_TYPE_OFFLINE, 'offline', ''), + self.presence = dbus.Struct((cs.PRESENCE_OFFLINE, 'offline', ''), signature='uss') def change_self_ident(self, ident): @@ -461,7 +461,7 @@ class SimulatedConnection(object): else: # stub - MC doesn't care ret[contact] = dbus.Struct( - (cs.PRESENCE_TYPE_UNKNOWN, 'unknown', ''), + (cs.PRESENCE_UNKNOWN, 'unknown', ''), signature='uss') self.q.dbus_return(e.message, ret, signature='a{u(uss)}') @@ -497,12 +497,12 @@ class SimulatedConnection(object): def Connect(self, e): self.StatusChanged(cs.CONN_STATUS_CONNECTING, - cs.CONN_STATUS_REASON_REQUESTED) + cs.CSR_REQUESTED) self.q.dbus_return(e.message, signature='') def Disconnect(self, e): self.StatusChanged(cs.CONN_STATUS_DISCONNECTED, - cs.CONN_STATUS_REASON_REQUESTED) + cs.CSR_REQUESTED) self.q.dbus_return(e.message, signature='') for c in self.channels: c.close() @@ -546,8 +546,8 @@ class SimulatedConnection(object): self.q.dbus_emit(self.object_path, cs.CONN, 'StatusChanged', status, reason, signature='uu') if self.status == cs.CONN_STATUS_CONNECTED and self.has_presence: - if self.presence[0] == cs.PRESENCE_TYPE_OFFLINE: - self.presence = dbus.Struct((cs.PRESENCE_TYPE_AVAILABLE, + if self.presence[0] == cs.PRESENCE_OFFLINE: + self.presence = dbus.Struct((cs.PRESENCE_AVAILABLE, 'available', ''), signature='uss') self.q.dbus_emit(self.object_path, @@ -1043,7 +1043,7 @@ def expect_fakecm_connection(q, bus, mc, account, expected_params, q.expect('dbus-method-call', method='Connect', path=conn.object_path, handled=True) - conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE) + conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CSR_NONE_SPECIFIED) expect_after_connect = list(expect_after_connect) diff --git a/tests/twisted/servicetest.py b/tests/twisted/servicetest.py index 4dc604f..c464d8f 100644 --- a/tests/twisted/servicetest.py +++ b/tests/twisted/servicetest.py @@ -1,5 +1,5 @@ # Copyright (C) 2009 Nokia Corporation -# Copyright (C) 2009 Collabora Ltd. +# Copyright (C) 2009-2013 Collabora Ltd. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -17,30 +17,55 @@ # 02110-1301 USA """ -Infrastructure code for testing Mission Control +Infrastructure code for testing Telepathy services. """ from twisted.internet import glib2reactor from twisted.internet.protocol import Protocol, Factory, ClientFactory glib2reactor.install() import sys +import time +import os import pprint import unittest import dbus import dbus.lowlevel -import dbus.glib +from dbus.mainloop.glib import DBusGMainLoop +DBusGMainLoop(set_as_default=True) from twisted.internet import reactor -tp_name_prefix = 'org.freedesktop.Telepathy' -tp_path_prefix = '/org/freedesktop/Telepathy' +import constants as cs -class Event: +tp_name_prefix = cs.PREFIX +tp_path_prefix = cs.PATH_PREFIX + +class DictionarySupersetOf (object): + """Utility class for expecting "a dictionary with at least these keys".""" + def __init__(self, dictionary): + self._dictionary = dictionary + def __repr__(self): + return "DictionarySupersetOf(%s)" % self._dictionary + def __eq__(self, other): + """would like to just do: + return set(other.items()).issuperset(self._dictionary.items()) + but it turns out that this doesn't work if you have another dict + nested in the values of your dicts""" + try: + for k,v in self._dictionary.items(): + if k not in other or other[k] != v: + return False + return True + except TypeError: # other is not iterable + return False + +class Event(object): def __init__(self, type, **kw): self.__dict__.update(kw) self.type = type + (self.subqueue, self.subtype) = type.split ("-", 1) def __str__(self): return '\n'.join([ str(type(self)) ] + format_event(self)) @@ -48,7 +73,7 @@ class Event: def format_event(event): ret = ['- type %s' % event.type] - for key in dir(event): + for key in sorted(dir(event)): if key != 'type' and not key.startswith('_'): ret.append('- %s: %s' % ( key, pprint.pformat(getattr(event, key)))) @@ -61,16 +86,17 @@ def format_event(event): class EventPattern: def __init__(self, type, **properties): self.type = type - self.predicate = lambda x: True + self.predicate = None if 'predicate' in properties: self.predicate = properties['predicate'] del properties['predicate'] self.properties = properties + (self.subqueue, self.subtype) = type.split ("-", 1) def __repr__(self): properties = dict(self.properties) - if self.predicate: + if self.predicate is not None: properties['predicate'] = self.predicate return '%s(%r, **%r)' % ( @@ -87,7 +113,7 @@ class EventPattern: except AttributeError: return False - if self.predicate(event): + if self.predicate is None or self.predicate(event): return True return False @@ -112,8 +138,8 @@ class BaseEventQueue: def __init__(self, timeout=None): self.verbose = False - self.past_events = [] self.forbidden_events = set() + self.event_queues = {} if timeout is None: self.timeout = 5 @@ -124,28 +150,14 @@ class BaseEventQueue: if self.verbose: print s - def log_event(self, event): - if self.verbose: - self.log('got event:') - - if self.verbose: - map(self.log, format_event(event)) + def log_queues(self, queues): + self.log ("Waiting for event on: %s" % ", ".join(queues)) - def flush_past_events(self): - self.past_events = [] - - def expect_racy(self, type, **kw): - pattern = EventPattern(type, **kw) - - for event in self.past_events: - if pattern.match(event): - self.log('past event handled') - map(self.log, format_event(event)) - self.log('') - self.past_events.remove(event) - return event + def log_event(self, event): + self.log('got event:') - return self.expect(type, **kw) + if self.verbose: + map(self.log, format_event(event)) def forbid_events(self, patterns): """ @@ -163,34 +175,79 @@ class BaseEventQueue: """ self.forbidden_events.difference_update(set(patterns)) + def unforbid_all(self): + """ + Remove all patterns from the set of forbidden events. + """ + self.forbidden_events.clear() + def _check_forbidden(self, event): for e in self.forbidden_events: if e.match(event): raise ForbiddenEventOccurred(event) def expect(self, type, **kw): + """ + Waits for an event matching the supplied pattern to occur, and returns + it. For example, to await a D-Bus signal with particular arguments: + + e = q.expect('dbus-signal', signal='Badgers', args=["foo", 42]) + """ pattern = EventPattern(type, **kw) + t = time.time() while True: - event = self.wait() - self.log_event(event) + event = self.wait([pattern.subqueue]) self._check_forbidden(event) if pattern.match(event): - self.log('handled') + self.log('handled, took %0.3f ms' + % ((time.time() - t) * 1000.0) ) self.log('') return event - self.past_events.append(event) self.log('not handled') self.log('') def expect_many(self, *patterns): + """ + Waits for events matching all of the supplied EventPattern instances to + return, and returns a list of events in the same order as the patterns + they matched. After a pattern is successfully matched, it is not + considered for future events; if more than one unsatisfied pattern + matches an event, the first "wins". + + Note that the expected events may occur in any order. If you're + expecting a series of events in a particular order, use repeated calls + to expect() instead. + + This method is useful when you're awaiting a number of events which may + happen in any order. For instance, in telepathy-gabble, calling a D-Bus + method often causes a value to be returned immediately, as well as a + query to be sent to the server. Since these events may reach the test + in either order, the following is incorrect and will fail if the IQ + happens to reach the test first: + + ret = q.expect('dbus-return', method='Foo') + query = q.expect('stream-iq', query_ns=ns.FOO) + + The following would be correct: + + ret, query = q.expect_many( + EventPattern('dbus-return', method='Foo'), + EventPattern('stream-iq', query_ns=ns.FOO), + ) + """ ret = [None] * len(patterns) + t = time.time() while None in ret: try: - event = self.wait() + queues = set() + for i, pattern in enumerate(patterns): + if ret[i] is None: + queues.add(pattern.subqueue) + event = self.wait(queues) except TimeoutError: self.log('timeout') self.log('still expecting:') @@ -198,17 +255,16 @@ class BaseEventQueue: if ret[i] is None: self.log(' - %r' % pattern) raise - self.log_event(event) self._check_forbidden(event) for i, pattern in enumerate(patterns): if ret[i] is None and pattern.match(event): - self.log('handled') + self.log('handled, took %0.3f ms' + % ((time.time() - t) * 1000.0) ) self.log('') ret[i] = event break else: - self.past_events.append(event) self.log('not handled') self.log('') @@ -217,8 +273,7 @@ class BaseEventQueue: def demand(self, type, **kw): pattern = EventPattern(type, **kw) - event = self.wait() - self.log_event(event) + event = self.wait([pattern.subqueue]) if pattern.match(event): self.log('handled') @@ -228,19 +283,39 @@ class BaseEventQueue: self.log('not handled') raise RuntimeError('expected %r, got %r' % (pattern, event)) + def queues_available(self, queues): + if queues == None: + return self.event_queues.keys() + else: + available = self.event_queues.keys() + return filter(lambda x: x in available, queues) + + + def pop_next(self, queue): + events = self.event_queues[queue] + e = events.pop(0) + if not events: + self.event_queues.pop (queue) + return e + + def append(self, event): + self.log ("Adding to queue") + self.log_event (event) + self.event_queues[event.subqueue] = \ + self.event_queues.get(event.subqueue, []) + [event] + class IteratingEventQueue(BaseEventQueue): """Event queue that works by iterating the Twisted reactor.""" def __init__(self, timeout=None): BaseEventQueue.__init__(self, timeout) - self.events = [] self._dbus_method_impls = [] self._buses = [] # a message filter which will claim we handled everything self._dbus_dev_null = \ lambda bus, message: dbus.lowlevel.HANDLER_RESULT_HANDLED - def wait(self): + def wait(self, queues=None): stop = [False] def later(): @@ -248,21 +323,21 @@ class IteratingEventQueue(BaseEventQueue): delayed_call = reactor.callLater(self.timeout, later) - while (not self.events) and (not stop[0]): - reactor.iterate(0.1) + self.log_queues(queues) - if self.events: + qa = self.queues_available(queues) + while not qa and (not stop[0]): + reactor.iterate(0.01) + qa = self.queues_available(queues) + + if qa: delayed_call.cancel() - return self.events.pop(0) + e = self.pop_next (qa[0]) + self.log_event (e) + return e else: raise TimeoutError - def append(self, event): - self.events.append(event) - - # compatibility - handle_event = append - def add_dbus_method_impl(self, cb, bus=None, **kwargs): if bus is None: bus = self._buses[0] @@ -387,50 +462,74 @@ class IteratingEventQueue(BaseEventQueue): class TestEventQueue(BaseEventQueue): def __init__(self, events): BaseEventQueue.__init__(self) - self.events = events + for e in events: + self.append (e) - def wait(self): - if self.events: - return self.events.pop(0) + def wait(self, queues = None): + qa = self.queues_available(queues) + + if qa: + return self.pop_next (qa[0]) else: raise TimeoutError class EventQueueTest(unittest.TestCase): def test_expect(self): - queue = TestEventQueue([Event('foo'), Event('bar')]) - assert queue.expect('foo').type == 'foo' - assert queue.expect('bar').type == 'bar' + queue = TestEventQueue([Event('test-foo'), Event('test-bar')]) + assert queue.expect('test-foo').type == 'test-foo' + assert queue.expect('test-bar').type == 'test-bar' def test_expect_many(self): - queue = TestEventQueue([Event('foo'), Event('bar')]) + queue = TestEventQueue([Event('test-foo'), + Event('test-bar')]) bar, foo = queue.expect_many( - EventPattern('bar'), - EventPattern('foo')) - assert bar.type == 'bar' - assert foo.type == 'foo' + EventPattern('test-bar'), + EventPattern('test-foo')) + assert bar.type == 'test-bar' + assert foo.type == 'test-foo' def test_expect_many2(self): # Test that events are only matched against patterns that haven't yet # been matched. This tests a regression. - queue = TestEventQueue([Event('foo', x=1), Event('foo', x=2)]) + queue = TestEventQueue([Event('test-foo', x=1), Event('test-foo', x=2)]) foo1, foo2 = queue.expect_many( - EventPattern('foo'), - EventPattern('foo')) - assert foo1.type == 'foo' and foo1.x == 1 - assert foo2.type == 'foo' and foo2.x == 2 + EventPattern('test-foo'), + EventPattern('test-foo')) + assert foo1.type == 'test-foo' and foo1.x == 1 + assert foo2.type == 'test-foo' and foo2.x == 2 + + def test_expect_queueing(self): + queue = TestEventQueue([Event('foo-test', x=1), + Event('foo-test', x=2)]) + + queue.append(Event('bar-test', x=1)) + queue.append(Event('bar-test', x=2)) + + queue.append(Event('baz-test', x=1)) + queue.append(Event('baz-test', x=2)) + + for x in xrange(1,2): + e = queue.expect ('baz-test') + assertEquals (x, e.x) + + e = queue.expect ('bar-test') + assertEquals (x, e.x) + + e = queue.expect ('foo-test') + assertEquals (x, e.x) def test_timeout(self): queue = TestEventQueue([]) - self.assertRaises(TimeoutError, queue.expect, 'foo') + self.assertRaises(TimeoutError, queue.expect, 'test-foo') def test_demand(self): - queue = TestEventQueue([Event('foo'), Event('bar')]) - foo = queue.demand('foo') - assert foo.type == 'foo' + queue = TestEventQueue([Event('test-foo'), Event('test-bar')]) + foo = queue.demand('test-foo') + assert foo.type == 'test-foo' def test_demand_fail(self): - queue = TestEventQueue([Event('foo'), Event('bar')]) - self.assertRaises(RuntimeError, queue.demand, 'bar') + queue = TestEventQueue([Event('test-foo'), Event('test-bar')]) + self.assertRaises(RuntimeError, queue.demand, 'test-bar') def unwrap(x): """Hack to unwrap D-Bus values, so that they're easier to read when @@ -459,11 +558,11 @@ def call_async(test, proxy, method, *args, **kw): resulting method return/error.""" def reply_func(*ret): - test.handle_event(Event('dbus-return', method=method, + test.append(Event('dbus-return', method=method, value=unwrap(ret))) def error_func(err): - test.handle_event(Event('dbus-error', method=method, error=err, + test.append(Event('dbus-error', method=method, error=err, name=err.get_dbus_name(), message=str(err))) method_proxy = getattr(proxy, method) @@ -481,7 +580,7 @@ def sync_dbus(bus, q, proxy): q.expect('dbus-error', method='DummySyncDBus') class ProxyWrapper: - def __init__(self, object, default, others): + def __init__(self, object, default, others={}): self.object = object self.default_interface = dbus.Interface(object, default) self.Properties = dbus.Interface(object, dbus.PROPERTIES_IFACE) @@ -500,6 +599,41 @@ class ProxyWrapper: return getattr(self.default_interface, name) +class ConnWrapper(ProxyWrapper): + def inspect_contact_sync(self, handle): + return self.inspect_contacts_sync([handle])[0] + + def inspect_contacts_sync(self, handles): + h2asv = self.Contacts.GetContactAttributes(handles, [], True) + ret = [] + for h in handles: + ret.append(h2asv[h][cs.ATTR_CONTACT_ID]) + return ret + + def get_contact_handle_sync(self, identifier): + return self.Contacts.GetContactByID(identifier, [])[0] + + def get_contact_handles_sync(self, ids): + return [self.get_contact_handle_sync(i) for i in ids] + +def wrap_connection(conn): + return ConnWrapper(conn, tp_name_prefix + '.Connection', + dict([ + (name, tp_name_prefix + '.Connection.Interface.' + name) + for name in ['Aliasing', 'Avatars', 'Capabilities', 'Contacts', + 'SimplePresence', 'Requests']] + + [('Peer', 'org.freedesktop.DBus.Peer'), + ('ContactCapabilities', cs.CONN_IFACE_CONTACT_CAPS), + ('ContactInfo', cs.CONN_IFACE_CONTACT_INFO), + ('Location', cs.CONN_IFACE_LOCATION), + ('Future', tp_name_prefix + '.Connection.FUTURE'), + ('MailNotification', cs.CONN_IFACE_MAIL_NOTIFICATION), + ('ContactList', cs.CONN_IFACE_CONTACT_LIST), + ('ContactGroups', cs.CONN_IFACE_CONTACT_GROUPS), + ('PowerSaving', cs.CONN_IFACE_POWER_SAVING), + ('Addressing', cs.CONN_IFACE_ADDRESSING), + ])) + def wrap_channel(chan, type_, extra=None): interfaces = { type_: tp_name_prefix + '.Channel.Type.' + type_, @@ -513,14 +647,26 @@ def wrap_channel(chan, type_, extra=None): return ProxyWrapper(chan, tp_name_prefix + '.Channel', interfaces) + +def wrap_content(chan, extra=None): + interfaces = { } + + if extra: + interfaces.update(dict([ + (name, tp_name_prefix + '.Call1.Content.Interface.' + name) + for name in extra])) + + return ProxyWrapper(chan, tp_name_prefix + '.Call1.Content', interfaces) + def make_connection(bus, event_func, name, proto, params): cm = bus.get_object( tp_name_prefix + '.ConnectionManager.%s' % name, - tp_path_prefix + '/ConnectionManager/%s' % name) + tp_path_prefix + '/ConnectionManager/%s' % name, + introspect=False) cm_iface = dbus.Interface(cm, tp_name_prefix + '.ConnectionManager') connection_name, connection_path = cm_iface.RequestConnection( - proto, params) + proto, dbus.Dictionary(params, signature='sv')) conn = wrap_connection(bus.get_object(connection_name, connection_path)) return conn @@ -540,7 +686,7 @@ class EventProtocol(Protocol): def dataReceived(self, data): if self.queue is not None: - self.queue.handle_event(Event('socket-data', protocol=self, + self.queue.append(Event('socket-data', protocol=self, data=data)) def sendData(self, data): @@ -552,7 +698,7 @@ class EventProtocol(Protocol): def connectionLost(self, reason=None): if self.queue is not None: - self.queue.handle_event(Event('socket-disconnected', protocol=self)) + self.queue.append(Event('socket-disconnected', protocol=self)) class EventProtocolFactory(Factory): def __init__(self, queue, block_reading=False): @@ -564,7 +710,7 @@ class EventProtocolFactory(Factory): def buildProtocol(self, addr): proto = self._create_protocol() - self.queue.handle_event(Event('socket-connected', protocol=proto)) + self.queue.append(Event('socket-connected', protocol=proto)) return proto class EventProtocolClientFactory(EventProtocolFactory, ClientFactory): @@ -572,7 +718,7 @@ class EventProtocolClientFactory(EventProtocolFactory, ClientFactory): def watch_tube_signals(q, tube): def got_signal_cb(*args, **kwargs): - q.handle_event(Event('tube-signal', + q.append(Event('tube-signal', path=kwargs['path'], signal=kwargs['member'], args=map(unwrap, args), @@ -590,6 +736,15 @@ def assertEquals(expected, value): raise AssertionError( "expected:\n%s\ngot:\n%s" % (pretty(expected), pretty(value))) +def assertSameSets(expected, value): + exp_set = set(expected) + val_set = set(value) + + if exp_set != val_set: + raise AssertionError( + "expected contents:\n%s\ngot:\n%s" % ( + pretty(exp_set), pretty(val_set))) + def assertNotEquals(expected, value): if expected == value: raise AssertionError( @@ -624,15 +779,11 @@ def assertFlagsUnset(flags, value): "expected none of flags %u, but %u are set in %u" % ( flags, masked, value)) -def assertSameSets(expected, value): - exp_set = set(expected) - val_set = set(value) - - if exp_set != val_set: +def assertDBusError(name, error): + if error.get_dbus_name() != name: raise AssertionError( - "expected contents:\n%s\ngot:\n%s" % ( - pretty(exp_set), pretty(val_set))) - + "expected DBus error named:\n %s\ngot:\n %s\n(with message: %s)" + % (name, error.get_dbus_name(), error.message)) def install_colourer(): def red(s): @@ -652,14 +803,26 @@ def install_colourer(): self.patterns = patterns def write(self, s): - f = self.patterns.get(s, lambda x: x) - self.fh.write(f(s)) + for p, f in self.patterns.items(): + if s.startswith(p): + self.fh.write(f(p) + s[len(p):]) + return + + self.fh.write(s) sys.stdout = Colourer(sys.stdout, patterns) return sys.stdout +# this is just to shut up unittest. +class DummyStream(object): + def write(self, s): + if 'CHECK_TWISTED_VERBOSE' in os.environ: + print s, + def flush(self): + pass if __name__ == '__main__': - unittest.main() - + stream = DummyStream() + runner = unittest.TextTestRunner(stream=stream) + unittest.main(testRunner=runner) -- 1.8.4.rc3