[telepathy-mission-control/master] Add a regression test for auto-away on system idle
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Apr 13 03:55:42 PDT 2009
This should eventually be in a plugin or a device-specific build of MC,
but for now MC is responsible for it, so we should test it.
---
test/twisted/Makefile.am | 1 +
test/twisted/account-manager/auto-away.py | 194 +++++++++++++++++++++++++++++
test/twisted/constants.py | 1 +
test/twisted/mc-debug-server.c | 36 ++++++
4 files changed, 232 insertions(+), 0 deletions(-)
create mode 100644 test/twisted/account-manager/auto-away.py
diff --git a/test/twisted/Makefile.am b/test/twisted/Makefile.am
index 0c0b122..5d70c9e 100644
--- a/test/twisted/Makefile.am
+++ b/test/twisted/Makefile.am
@@ -2,6 +2,7 @@ TWISTED_TESTS =
TWISTED_BASIC_TESTS = \
account-bad-cm.py \
+ account-manager/auto-away.py \
account-requests/cancel.py \
account-requests/create-text.py \
account-requests/delete-account-during-request.py \
diff --git a/test/twisted/account-manager/auto-away.py b/test/twisted/account-manager/auto-away.py
new file mode 100644
index 0000000..7b525f4
--- /dev/null
+++ b/test/twisted/account-manager/auto-away.py
@@ -0,0 +1,194 @@
+import dbus
+import dbus.service
+
+from servicetest import EventPattern, tp_name_prefix, tp_path_prefix
+from mctest import exec_test, SimulatedConnection, create_fakecm_account,\
+ SimulatedChannel
+import constants as cs
+
+class PresenceConnection(SimulatedConnection):
+ def GetInterfaces(self, e):
+ self.q.dbus_return(e.message, [cs.CONN_IFACE_REQUESTS,
+ cs.CONN_IFACE_SIMPLE_PRESENCE], signature='as')
+
+def test(q, bus, mc):
+ cm_name_ref = dbus.service.BusName(
+ tp_name_prefix + '.ConnectionManager.fakecm', bus=bus)
+
+ # Create an account
+ params = dbus.Dictionary({"account": "someguy at example.com",
+ "password": "secrecy"}, signature='sv')
+ (cm_name_ref, account) = create_fakecm_account(q, bus, mc, params)
+
+ # The account is initially valid but disabled
+ assert not account.Get(cs.ACCOUNT, 'Enabled',
+ dbus_interface=cs.PROPERTIES_IFACE)
+ assert account.Get(cs.ACCOUNT, 'Valid',
+ dbus_interface=cs.PROPERTIES_IFACE)
+
+ # Enable the account
+ account.Set(cs.ACCOUNT, 'Enabled', True,
+ dbus_interface=cs.PROPERTIES_IFACE)
+ q.expect('dbus-signal',
+ path=account.object_path,
+ signal='AccountPropertyChanged',
+ interface=cs.ACCOUNT)
+
+ assert account.Get(cs.ACCOUNT, 'Enabled',
+ dbus_interface=cs.PROPERTIES_IFACE)
+ assert account.Get(cs.ACCOUNT, 'Valid',
+ dbus_interface=cs.PROPERTIES_IFACE)
+
+ # Check the requested presence is offline
+ properties = account.GetAll(cs.ACCOUNT,
+ dbus_interface=cs.PROPERTIES_IFACE)
+ assert properties is not None
+ # the requested presence is defined by Connection_Presence_Type:
+ # Connection_Presence_Type_Unset = 0
+ # Connection_Presence_Type_Offline = 1
+ # Connection_Presence_Type_Available = 2
+ assert properties.get('RequestedPresence') == \
+ dbus.Struct((dbus.UInt32(0L), dbus.String(u''), dbus.String(u''))), \
+ properties.get('RequestedPresence') # FIXME: we should expect 1
+
+ # Go online
+ requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_AVAILABLE),
+ dbus.String(u'available'), dbus.String(u'staring at the sea')))
+ account.Set(cs.ACCOUNT,
+ 'RequestedPresence', requested_presence,
+ dbus_interface=cs.PROPERTIES_IFACE)
+
+ e = q.expect('dbus-method-call', method='RequestConnection',
+ args=['fakeprotocol', params],
+ destination=tp_name_prefix + '.ConnectionManager.fakecm',
+ path=tp_path_prefix + '/ConnectionManager/fakecm',
+ interface=tp_name_prefix + '.ConnectionManager',
+ handled=False)
+
+ conn = PresenceConnection(q, bus, 'fakecm', 'fakeprotocol', '_',
+ 'myself')
+
+ q.dbus_return(e.message, conn.bus_name, conn.object_path, signature='so')
+
+ # MC calls GetStatus (maybe) and then Connect
+
+ q.expect('dbus-method-call', method='Connect',
+ path=conn.object_path, handled=True)
+
+ # Connect succeeds
+ conn.StatusChanged(cs.CONN_STATUS_CONNECTED, cs.CONN_STATUS_REASON_NONE)
+
+ # MC does some setup, including fetching the list of Channels
+
+ _, get_statuses = q.expect_many(
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='GetAll',
+ args=[cs.CONN_IFACE_REQUESTS],
+ path=conn.object_path, handled=True),
+ EventPattern('dbus-method-call',
+ interface=cs.PROPERTIES_IFACE, method='Get',
+ args=[cs.CONN_IFACE_SIMPLE_PRESENCE, 'Statuses'],
+ path=conn.object_path, handled=False),
+ )
+ q.dbus_return(get_statuses.message,
+ dbus.Dictionary({
+ 'available': (cs.PRESENCE_TYPE_AVAILABLE, True, True),
+ 'away': (cs.PRESENCE_TYPE_AWAY, True, True),
+ 'busy': (cs.PRESENCE_TYPE_BUSY, True, True),
+ 'offline': (cs.PRESENCE_TYPE_OFFLINE, False, False),
+ }, signature='s(ubb)'),
+ signature='v')
+
+ e = q.expect('dbus-method-call',
+ path=conn.object_path,
+ interface=cs.CONN_IFACE_SIMPLE_PRESENCE, method='SetPresence',
+ args=['available', 'staring at the sea'],
+ handled=False)
+ q.dbus_return(e.message, signature='')
+
+ # Check the requested presence is online
+ properties = account.GetAll(cs.ACCOUNT,
+ dbus_interface=cs.PROPERTIES_IFACE)
+ assert properties is not None
+ assert properties.get('RequestedPresence') == requested_presence, \
+ properties.get('RequestedPresence')
+
+ # This is normally a C API, only exposed to D-Bus here for testing
+ secret_debug_api = dbus.Interface(bus.get_object(cs.AM, "/"),
+ 'org.freedesktop.Telepathy.MissionControl.RegressionTests')
+ MCD_SYSTEM_IDLE = 32
+
+ # Set the idle flag
+ secret_debug_api.ChangeSystemFlags(dbus.UInt32(MCD_SYSTEM_IDLE),
+ dbus.UInt32(0))
+
+ e = q.expect('dbus-method-call',
+ path=conn.object_path,
+ interface=cs.CONN_IFACE_SIMPLE_PRESENCE, method='SetPresence',
+ args=['away', ''],
+ handled=False)
+ q.dbus_return(e.message, signature='')
+
+ # Unset the idle flag
+ secret_debug_api.ChangeSystemFlags(dbus.UInt32(0),
+ dbus.UInt32(MCD_SYSTEM_IDLE))
+
+ # MC puts the account back online
+
+ e = q.expect('dbus-method-call',
+ path=conn.object_path,
+ interface=cs.CONN_IFACE_SIMPLE_PRESENCE, method='SetPresence',
+ args=['available', 'staring at the sea'],
+ handled=False)
+ q.dbus_return(e.message, signature='')
+
+ # Go to a non-Available status
+ requested_presence = dbus.Struct((dbus.UInt32(cs.PRESENCE_TYPE_BUSY),
+ dbus.String(u'busy'), dbus.String(u'in the great below')))
+ account.Set(cs.ACCOUNT,
+ 'RequestedPresence', requested_presence,
+ dbus_interface=cs.PROPERTIES_IFACE)
+ e = q.expect('dbus-method-call',
+ path=conn.object_path,
+ interface=cs.CONN_IFACE_SIMPLE_PRESENCE, method='SetPresence',
+ args=['busy', 'in the great below'],
+ handled=False)
+ q.dbus_return(e.message, signature='')
+
+ forbidden = [EventPattern('dbus-method-call',
+ path=conn.object_path,
+ interface=cs.CONN_IFACE_SIMPLE_PRESENCE, method='SetPresence')]
+ q.forbid_events(forbidden)
+
+ # Set the idle flag
+ secret_debug_api.ChangeSystemFlags(dbus.UInt32(MCD_SYSTEM_IDLE),
+ dbus.UInt32(0))
+
+ # MC does not put the account away
+
+ # Unset the idle flag
+ secret_debug_api.ChangeSystemFlags(dbus.UInt32(0),
+ dbus.UInt32(MCD_SYSTEM_IDLE))
+
+ # MC does not put the account back online
+
+ q.unforbid_events(forbidden)
+
+ # Put the account offline
+ requested_presence = (dbus.UInt32(cs.PRESENCE_TYPE_OFFLINE), 'offline', '')
+ account.Set(cs.ACCOUNT,
+ 'RequestedPresence', requested_presence,
+ dbus_interface=cs.PROPERTIES_IFACE)
+
+ # In response, MC tells us to Disconnect, and we do
+ q.expect('dbus-method-call', method='Disconnect',
+ path=conn.object_path, handled=True)
+
+ properties = account.GetAll(cs.ACCOUNT, dbus_interface=cs.PROPERTIES_IFACE)
+ assert properties['Connection'] == '/'
+ assert properties['ConnectionStatus'] == cs.CONN_STATUS_DISCONNECTED
+ assert properties['CurrentPresence'] == requested_presence
+ assert properties['RequestedPresence'] == requested_presence
+
+if __name__ == '__main__':
+ exec_test(test, {})
diff --git a/test/twisted/constants.py b/test/twisted/constants.py
index 72cb159..61ec974 100644
--- a/test/twisted/constants.py
+++ b/test/twisted/constants.py
@@ -38,6 +38,7 @@ CONN = tp_name_prefix + ".Connection"
CONN_IFACE_CONTACTS = CONN + '.Interface.Contacts'
CONN_IFACE_CONTACT_CAPA = CONN + '.Interface.ContactCapabilities.DRAFT'
CONN_IFACE_REQUESTS = CONN + '.Interface.Requests'
+CONN_IFACE_SIMPLE_PRESENCE = CONN + '.Interface.SimplePresence'
CONN_STATUS_CONNECTED = 0
CONN_STATUS_CONNECTING = 1
diff --git a/test/twisted/mc-debug-server.c b/test/twisted/mc-debug-server.c
index 1bb640e..3b9912f 100644
--- a/test/twisted/mc-debug-server.c
+++ b/test/twisted/mc-debug-server.c
@@ -58,6 +58,42 @@ dbus_filter_function (DBusConnection *connection,
g_message ("Got disconnected from the session bus");
exit (69); /* EX_UNAVAILABLE */
}
+ else if (dbus_message_is_method_call (message,
+ "org.freedesktop.Telepathy.MissionControl.RegressionTests",
+ "ChangeSystemFlags"))
+ {
+ DBusMessage *reply;
+ DBusError e;
+ dbus_uint32_t set, unset;
+
+ dbus_error_init (&e);
+
+ if (!dbus_message_get_args (message, &e,
+ 'u', &set,
+ 'u', &unset,
+ DBUS_TYPE_INVALID))
+ {
+ reply = dbus_message_new_error (message, e.name, e.message);
+ dbus_error_free (&e);
+ }
+ else
+ {
+ McdMission *mission = MCD_MISSION (mcd_master_get_default ());
+ McdSystemFlags flags;
+
+ flags = mcd_mission_get_flags (mission);
+ flags |= set;
+ flags &= ~unset;
+ mcd_mission_set_flags (mission, flags);
+
+ reply = dbus_message_new_method_return (message);
+ }
+
+ if (reply == NULL || !dbus_connection_send (connection, reply, NULL))
+ g_error ("Out of memory");
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
--
1.5.6.5
More information about the telepathy-commits
mailing list