summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2010-04-21 19:51:07 +0100
committerWill Thompson <will.thompson@collabora.co.uk>2010-04-22 11:04:58 +0100
commit2fdde1bdc3b48c0ed20daf105a9516aa7fe4fb16 (patch)
tree0ddf435574c484a10ac1ac8d3184d1d0d77063f7
parent50cc4015c061d7d36dd190877b5a5d89596003dc (diff)
downloadtelepathy-gabble-2fdde1bdc3b48c0ed20daf105a9516aa7fe4fb16.tar.gz
Add a test for MCE device idleness support
-rw-r--r--configure.ac1
-rw-r--r--tests/twisted/Makefile.am8
-rw-r--r--tests/twisted/device-idleness.py89
-rw-r--r--tests/twisted/ns.py1
4 files changed, 99 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac
index 74dc3dbad..d4ab9f888 100644
--- a/configure.ac
+++ b/configure.ac
@@ -240,6 +240,7 @@ fi
dnl Check for MCE, a Maemo service used by Gabble to determine when the device
dnl is idle.
PKG_CHECK_MODULES([MCE], mce >= 1.5, [HAVE_MCE=yes], [HAVE_MCE=no])
+AM_CONDITIONAL([HAVE_MCE], [test x"$HAVE_MCE" = xyes])
if test x"$HAVE_MCE" = xyes; then
AC_DEFINE([HAVE_MCE], [1], [Define if mce is available])
fi
diff --git a/tests/twisted/Makefile.am b/tests/twisted/Makefile.am
index f497a9a03..c899b2e2e 100644
--- a/tests/twisted/Makefile.am
+++ b/tests/twisted/Makefile.am
@@ -15,6 +15,7 @@ TWISTED_TESTS = \
caps/receive-jingle.py \
caps/trust-thyself.py \
caps/tube-caps.py \
+ device-idleness.py \
muc/name-conflict.py \
muc/renamed.py \
muc/roomlist.py \
@@ -192,12 +193,19 @@ else
ENABLE_ASSUMED_FT_CAP_PYBOOL = False
endif
+if HAVE_MCE
+HAVE_MCE_PYBOOL = True
+else
+HAVE_MCE_PYBOOL = False
+endif
+
config.py: Makefile
$(QUIET_GEN) { \
echo "PACKAGE_STRING = \"$(PACKAGE_STRING)\""; \
echo "CLIENT_TYPE = '$(CLIENT_TYPE)'"; \
echo "DEBUGGING = $(DEBUGGING_PYBOOL)"; \
echo "ENABLE_ASSUMED_FT_CAP = $(ENABLE_ASSUMED_FT_CAP_PYBOOL)"; \
+ echo "HAVE_MCE = $(HAVE_MCE_PYBOOL)"; \
} > $@
BUILT_SOURCES = config.py
diff --git a/tests/twisted/device-idleness.py b/tests/twisted/device-idleness.py
new file mode 100644
index 000000000..8d5bb6259
--- /dev/null
+++ b/tests/twisted/device-idleness.py
@@ -0,0 +1,89 @@
+"""
+Test listening to device idleness status changes.
+
+When we're not building with MCE support, Gabble uses a test suite-specific
+service on the session bus. When we *are* building with MCE support, it uses
+the system bus, so we can't test it. Hence:
+"""
+
+import config
+
+if config.HAVE_MCE:
+ print "NOTE: built with real MCE support; skipping idleness test"
+ raise SystemExit(77)
+
+from functools import partial
+
+from gabbletest import exec_test, GoogleXmlStream
+from servicetest import call_async, Event, assertEquals
+import ns
+
+import dbus
+import dbus.service
+
+# Fake MCE constants, cloned from slacker.c
+MCE_SERVICE = "org.freedesktop.Telepathy.Gabble.Tests.MCE"
+
+MCE_SIGNAL_IF = "org.freedesktop.Telepathy.Gabble.Tests.MCE"
+MCE_INACTIVITY_SIG = "InactivityChanged"
+
+MCE_REQUEST_IF = "org.freedesktop.Telepathy.Gabble.Tests.MCE"
+MCE_REQUEST_PATH = "/org/freedesktop/Telepathy/Gabble/Tests/MCE"
+MCE_INACTIVITY_STATUS_GET = "GetInactivity"
+
+from twisted.internet import reactor
+
+class FakeMCE(dbus.service.Object):
+ def __init__(self, q, bus, inactive=False):
+ super(FakeMCE, self).__init__(bus, MCE_REQUEST_PATH)
+
+ self.q = q
+ self.inactive = inactive
+
+ @dbus.service.method(dbus_interface=MCE_REQUEST_IF,
+ in_signature='', out_signature='b')
+ def GetInactivity(self):
+ self.q.append(Event('get-inactivity-called'))
+ return self.inactive
+
+ @dbus.service.signal(dbus_interface=MCE_SIGNAL_IF, signature='b')
+ def InactivityChanged(self, new_value):
+ self.inactive = new_value
+
+
+def expect_command(q, inactive):
+ event = q.expect('stream-iq', query_name='query', query_ns=ns.GOOGLE_QUEUE)
+ command = event.query.firstChildElement()
+ assertEquals('enable' if inactive else 'disable', command.name)
+
+def test(q, bus, conn, stream, initially_inactive=False):
+ mce = FakeMCE(q, bus, initially_inactive)
+
+ call_async(q, conn, 'Connect')
+ q.expect('get-inactivity-called')
+
+ if initially_inactive:
+ expect_command(q, True)
+ else:
+ mce.InactivityChanged(True)
+ expect_command(q, True)
+
+ mce.InactivityChanged(False)
+ expect_command(q, False)
+
+ # Just cycle it a bit to check it doesn't blow up slowly
+ mce.InactivityChanged(True)
+ expect_command(q, True)
+
+ mce.InactivityChanged(False)
+ expect_command(q, False)
+
+ mce.remove_from_connection()
+
+if __name__ == '__main__':
+ dbus.SessionBus().request_name(MCE_SERVICE, 0)
+ try:
+ exec_test(partial(test, initially_inactive=False), protocol=GoogleXmlStream)
+ exec_test(partial(test, initially_inactive=True), protocol=GoogleXmlStream)
+ finally:
+ dbus.SessionBus().release_name(MCE_SERVICE)
diff --git a/tests/twisted/ns.py b/tests/twisted/ns.py
index 6d800360c..a36ebb198 100644
--- a/tests/twisted/ns.py
+++ b/tests/twisted/ns.py
@@ -12,6 +12,7 @@ GOOGLE_FEAT_VOICE = 'http://www.google.com/xmpp/protocol/voice/v1'
GOOGLE_FEAT_VIDEO = 'http://www.google.com/xmpp/protocol/video/v1'
GOOGLE_JINGLE_INFO = 'google:jingleinfo'
GOOGLE_P2P = "http://www.google.com/transport/p2p"
+GOOGLE_QUEUE = 'google:queue'
GOOGLE_ROSTER = 'google:roster'
GOOGLE_SESSION = "http://www.google.com/session"
GOOGLE_SESSION_PHONE = "http://www.google.com/session/phone"