diff options
author | Simon McVittie <smcv@collabora.com> | 2019-09-02 13:04:57 +0100 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2019-09-02 13:04:57 +0100 |
commit | d1d876399be089bd94343140da8d41479f0c1fd1 (patch) | |
tree | 02d65074a6d23a461568882e23f2495c653eb5d9 /test/test-p2p.py | |
parent | 5b0af53bbb3f4e12af4d979d8501ff6fa10af051 (diff) |
test-p2p: Add test coverage for sending and receiving fds
Signed-off-by: Simon McVittie <smcv@collabora.com>
Diffstat (limited to 'test/test-p2p.py')
-rwxr-xr-x | test/test-p2p.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/test-p2p.py b/test/test-p2p.py index d79d2c5..d895eff 100755 --- a/test/test-p2p.py +++ b/test/test-p2p.py @@ -29,10 +29,12 @@ import os import unittest import logging +import sys import dbus import dbus.glib import dbus.service +import dbus.types from dbus._compat import is_py2 @@ -82,6 +84,29 @@ class TestDBusBindings(unittest.TestCase): conn, unique = self.get_conn_and_unique() ret = conn.call_blocking(NAME, OBJECT, IFACE, 'Echo', 'v', ('V',)) self.assertEqual(ret, 'V') + self.assertEqual(ret.variant_level, 1) + + @unittest.skipIf(sys.platform.startswith("win"), "requires Unix") + def testUnixFd(self): + with open('/dev/null', 'r') as file_like: + for method in 'Echo', 'EchoVariant', 'EchoFd': + if method == 'EchoFd': + sig = 'h' + else: + sig = 'v' + + conn, unique = self.get_conn_and_unique() + ret = conn.call_blocking(NAME, OBJECT, IFACE, method, sig, (dbus.types.UnixFd(file_like),)) + self.assertEqual(type(ret), dbus.types.UnixFd) + + if method == 'EchoFd': + self.assertEqual(ret.variant_level, 0) + elif method == 'EchoVariant': + self.assertEqual(ret.variant_level, 1) + + plain_fd = ret.take() + self.assertTrue(os.path.sameopenfile(file_like.fileno(), plain_fd)) + os.close(plain_fd) def testCallThroughProxy(self): conn, unique = self.get_conn_and_unique() |