3 # Copyright (C) 2004 Red Hat Inc. <http://www.redhat.com/>
4 # Copyright (C) 2005, 2006 Collabora Ltd. <http://www.collabora.co.uk/>
6 # Licensed under the Academic Free License version 2.1
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 builddir
= os
.path
.normpath(os
.environ
["DBUS_TOP_BUILDDIR"])
31 pydir
= os
.path
.normpath(os
.environ
["DBUS_TOP_SRCDIR"])
41 logging
.getLogger().setLevel(1)
44 NAME
= "org.freedesktop.DBus.TestSuitePythonService"
45 IFACE
= "org.freedesktop.DBus.TestSuiteInterface"
46 OBJECT
= "/org/freedesktop/DBus/TestSuitePythonObject"
48 class TestDBusBindings(unittest
.TestCase
):
49 # This test case relies on the test service already having been activated.
51 def get_conn_and_unique(self
):
52 # since I haven't implemented servers yet, I'll use the bus daemon
53 # as our peer - note that there's no name tracking because we're not
54 # using dbus.bus.BusConnection!
55 conn
= dbus
.connection
.Connection(
56 os
.environ
['DBUS_SESSION_BUS_ADDRESS'])
57 unique
= conn
.call_blocking('org.freedesktop.DBus',
58 '/org/freedesktop/DBus',
59 'org.freedesktop.DBus', 'Hello',
60 '', (), utf8_strings
=True)
61 self
.assert_(unique
.__class
__ == dbus
.UTF8String
, repr(unique
))
62 self
.assert_(unique
.startswith(':'), unique
)
63 conn
.set_unique_name(unique
)
67 conn
, unique
= self
.get_conn_and_unique()
68 ret
= conn
.call_blocking(NAME
, OBJECT
, IFACE
, 'Echo', 'v', ('V',))
69 self
.assertEquals(ret
, 'V')
71 def testCallThroughProxy(self
):
72 conn
, unique
= self
.get_conn_and_unique()
73 proxy
= conn
.get_object(NAME
, OBJECT
)
74 iface
= dbus
.Interface(proxy
, IFACE
)
76 self
.assertEquals(ret
, 'V')
78 def testSetUniqueName(self
):
79 conn
, unique
= self
.get_conn_and_unique()
80 ret
= conn
.call_blocking(NAME
, OBJECT
, IFACE
,
81 'MethodExtraInfoKeywords', '', (),
83 self
.assertEquals(ret
, (unique
, OBJECT
, NAME
,
84 'dbus.lowlevel.MethodCallMessage'))
87 if __name__
== '__main__':
88 gobject
.threads_init()
89 dbus
.glib
.init_threads()