3 # Copyright (C) 2004 Red Hat Inc. <http://www.redhat.com/>
4 # Copyright (C) 2005-2007 Collabora Ltd. <http://www.collabora.co.uk/>
6 # Permission is hereby granted, free of charge, to any person
7 # obtaining a copy of this software and associated documentation
8 # files (the "Software"), to deal in the Software without
9 # restriction, including without limitation the rights to use, copy,
10 # modify, merge, publish, distribute, sublicense, and/or sell copies
11 # of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 # DEALINGS IN THE SOFTWARE.
34 builddir
= os
.path
.normpath(os
.environ
["DBUS_TOP_BUILDDIR"])
35 pydir
= os
.path
.normpath(os
.environ
["DBUS_TOP_SRCDIR"])
45 logging
.getLogger().setLevel(1)
48 NAME
= "org.freedesktop.DBus.TestSuitePythonService"
49 IFACE
= "org.freedesktop.DBus.TestSuiteInterface"
50 OBJECT
= "/org/freedesktop/DBus/TestSuitePythonObject"
52 class TestDBusBindings(unittest
.TestCase
):
53 # This test case relies on the test service already having been activated.
55 def get_conn_and_unique(self
):
56 # since I haven't implemented servers yet, I'll use the bus daemon
57 # as our peer - note that there's no name tracking because we're not
58 # using dbus.bus.BusConnection!
59 conn
= dbus
.connection
.Connection(
60 os
.environ
['DBUS_SESSION_BUS_ADDRESS'])
61 unique
= conn
.call_blocking('org.freedesktop.DBus',
62 '/org/freedesktop/DBus',
63 'org.freedesktop.DBus', 'Hello',
64 '', (), utf8_strings
=True)
65 self
.assert_(unique
.__class
__ == dbus
.UTF8String
, repr(unique
))
66 self
.assert_(unique
.startswith(':'), unique
)
67 conn
.set_unique_name(unique
)
71 conn
, unique
= self
.get_conn_and_unique()
72 ret
= conn
.call_blocking(NAME
, OBJECT
, IFACE
, 'Echo', 'v', ('V',))
73 self
.assertEquals(ret
, 'V')
75 def testCallThroughProxy(self
):
76 conn
, unique
= self
.get_conn_and_unique()
77 proxy
= conn
.get_object(NAME
, OBJECT
)
78 iface
= dbus
.Interface(proxy
, IFACE
)
80 self
.assertEquals(ret
, 'V')
82 def testSetUniqueName(self
):
83 conn
, unique
= self
.get_conn_and_unique()
84 ret
= conn
.call_blocking(NAME
, OBJECT
, IFACE
,
85 'MethodExtraInfoKeywords', '', (),
87 self
.assertEquals(ret
, (unique
, OBJECT
, NAME
,
88 'dbus.lowlevel.MethodCallMessage'))
91 if __name__
== '__main__':
92 gobject
.threads_init()
93 dbus
.glib
.init_threads()