|
Packit |
130fc8 |
#!/usr/bin/env python
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
# Copyright (C) 2004 Red Hat Inc. <http://www.redhat.com/>
|
|
Packit |
130fc8 |
# Copyright (C) 2005-2007 Collabora Ltd. <http://www.collabora.co.uk/>
|
|
Packit |
130fc8 |
#
|
|
Packit |
130fc8 |
# Permission is hereby granted, free of charge, to any person
|
|
Packit |
130fc8 |
# obtaining a copy of this software and associated documentation
|
|
Packit |
130fc8 |
# files (the "Software"), to deal in the Software without
|
|
Packit |
130fc8 |
# restriction, including without limitation the rights to use, copy,
|
|
Packit |
130fc8 |
# modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
Packit |
130fc8 |
# of the Software, and to permit persons to whom the Software is
|
|
Packit |
130fc8 |
# furnished to do so, subject to the following conditions:
|
|
Packit |
130fc8 |
#
|
|
Packit |
130fc8 |
# The above copyright notice and this permission notice shall be
|
|
Packit |
130fc8 |
# included in all copies or substantial portions of the Software.
|
|
Packit |
130fc8 |
#
|
|
Packit |
130fc8 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
Packit |
130fc8 |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
Packit |
130fc8 |
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
Packit |
130fc8 |
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
Packit |
130fc8 |
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
Packit |
130fc8 |
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
Packit |
130fc8 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
Packit |
130fc8 |
# DEALINGS IN THE SOFTWARE.
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
import os
|
|
Packit |
130fc8 |
import unittest
|
|
Packit |
130fc8 |
import logging
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
import dbus
|
|
Packit |
130fc8 |
import dbus.glib
|
|
Packit |
130fc8 |
import dbus.service
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
from dbus._compat import is_py2
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
try:
|
|
Packit |
130fc8 |
from gi.repository import GObject as gobject
|
|
Packit |
130fc8 |
except ImportError:
|
|
Packit |
130fc8 |
raise SystemExit(77)
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
logging.basicConfig()
|
|
Packit |
130fc8 |
logging.getLogger().setLevel(1)
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
NAME = "org.freedesktop.DBus.TestSuitePythonService"
|
|
Packit |
130fc8 |
IFACE = "org.freedesktop.DBus.TestSuiteInterface"
|
|
Packit |
130fc8 |
OBJECT = "/org/freedesktop/DBus/TestSuitePythonObject"
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
class TestDBusBindings(unittest.TestCase):
|
|
Packit |
130fc8 |
# This test case relies on the test service already having been activated.
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
def get_conn_and_unique(self):
|
|
Packit |
130fc8 |
# since I haven't implemented servers yet, I'll use the bus daemon
|
|
Packit |
130fc8 |
# as our peer - note that there's no name tracking because we're not
|
|
Packit |
130fc8 |
# using dbus.bus.BusConnection!
|
|
Packit |
130fc8 |
conn = dbus.connection.Connection(
|
|
Packit |
130fc8 |
os.environ['DBUS_SESSION_BUS_ADDRESS'])
|
|
Packit |
130fc8 |
kwargs = {}
|
|
Packit |
130fc8 |
if is_py2:
|
|
Packit |
130fc8 |
kwargs['utf8_strings'] = True
|
|
Packit |
130fc8 |
unique = conn.call_blocking('org.freedesktop.DBus',
|
|
Packit |
130fc8 |
'/org/freedesktop/DBus',
|
|
Packit |
130fc8 |
'org.freedesktop.DBus', 'Hello',
|
|
Packit |
130fc8 |
'', (), **kwargs)
|
|
Packit |
130fc8 |
if is_py2:
|
|
Packit |
130fc8 |
self.assertTrue(unique.__class__ == dbus.UTF8String, repr(unique))
|
|
Packit |
130fc8 |
self.assertTrue(unique.startswith(':'), unique)
|
|
Packit |
130fc8 |
conn.set_unique_name(unique)
|
|
Packit |
130fc8 |
return conn, unique
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
def testCall(self):
|
|
Packit |
130fc8 |
conn, unique = self.get_conn_and_unique()
|
|
Packit |
130fc8 |
ret = conn.call_blocking(NAME, OBJECT, IFACE, 'Echo', 'v', ('V',))
|
|
Packit |
130fc8 |
self.assertEqual(ret, 'V')
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
def testCallThroughProxy(self):
|
|
Packit |
130fc8 |
conn, unique = self.get_conn_and_unique()
|
|
Packit |
130fc8 |
proxy = conn.get_object(NAME, OBJECT)
|
|
Packit |
130fc8 |
iface = dbus.Interface(proxy, IFACE)
|
|
Packit |
130fc8 |
ret = iface.Echo('V')
|
|
Packit |
130fc8 |
self.assertEqual(ret, 'V')
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
def testSetUniqueName(self):
|
|
Packit |
130fc8 |
conn, unique = self.get_conn_and_unique()
|
|
Packit |
130fc8 |
kwargs = {}
|
|
Packit |
130fc8 |
if is_py2:
|
|
Packit |
130fc8 |
kwargs['utf8_strings'] = True
|
|
Packit |
130fc8 |
ret = conn.call_blocking(NAME, OBJECT, IFACE,
|
|
Packit |
130fc8 |
'MethodExtraInfoKeywords', '', (),
|
|
Packit |
130fc8 |
**kwargs)
|
|
Packit |
130fc8 |
self.assertEqual(ret, (unique, OBJECT, NAME,
|
|
Packit |
130fc8 |
'dbus.lowlevel.MethodCallMessage'))
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
if __name__ == '__main__':
|
|
Packit |
130fc8 |
gobject.threads_init()
|
|
Packit |
130fc8 |
dbus.glib.init_threads()
|
|
Packit |
130fc8 |
|
|
Packit |
130fc8 |
unittest.main()
|