Revert "Make sure extensions are built before docs; get rid of strange inter-director...
[dbus-python-phuang.git] / test / test-p2p.py
blob8494f23523897d071a83b464437a1d927cf91748
1 #!/usr/bin/env python
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.
27 import sys
28 import os
29 import unittest
30 import time
31 import logging
32 import weakref
34 builddir = os.path.normpath(os.environ["DBUS_TOP_BUILDDIR"])
35 pydir = os.path.normpath(os.environ["DBUS_TOP_SRCDIR"])
37 import dbus
38 import _dbus_bindings
39 import gobject
40 import dbus.glib
41 import dbus.service
44 logging.basicConfig()
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)
68 return conn, unique
70 def testCall(self):
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)
79 ret = iface.Echo('V')
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', '', (),
86 utf8_strings=True)
87 self.assertEquals(ret, (unique, OBJECT, NAME,
88 'dbus.lowlevel.MethodCallMessage'))
91 if __name__ == '__main__':
92 gobject.threads_init()
93 dbus.glib.init_threads()
95 unittest.main()