diff --git a/src/tests/dbusmock-templates/colord.py b/src/tests/dbusmock-templates/colord.py new file mode 100644 index 000000000..c3901dbbd --- /dev/null +++ b/src/tests/dbusmock-templates/colord.py @@ -0,0 +1,81 @@ +'''colord proxy mock template +''' + +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 3 of the License, or (at your option) any +# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text +# of the license. + +__author__ = 'Jonas Ã…dahl' +__copyright__ = '(c) 2021 Red Hat Inc.' + +import dbus +import os +import pwd +from dbusmock import MOCK_IFACE + + +BUS_PREFIX = 'org.freedesktop.ColorManager' +PATH_PREFIX = '/org/freedesktop/ColorManager' + +BUS_NAME = BUS_PREFIX +MAIN_OBJ = PATH_PREFIX +MAIN_IFACE = BUS_NAME +DEVICE_IFACE = BUS_PREFIX + '.Device' +SYSTEM_BUS = True + + +def load(mock, parameters=None): + mock.devices = {} + +def escape_unit_name(name): + for s in ['.', '-', '\'', ' ']: + name = name.replace(s, '_') + return name + +def get_username(uid): + return pwd.getpwuid(uid).pw_name + +def device_id_from_path(mock, path): + for device_id in mock.devices: + device_path = mock.devices[device_id] + if device_path == path: + return device_id + return None + +@dbus.service.method(MAIN_IFACE, in_signature='ssa{sv}', out_signature='o') +def CreateDevice(self, device_id, scope, props): + uid = os.getuid() + username = get_username(uid) + device_path = PATH_PREFIX + '/devices/' + \ + escape_unit_name(device_id) + \ + '_' + username + '_' + str(uid) + self.devices[device_id] = device_path + self.AddObject(device_path, + DEVICE_IFACE, + { + 'DeviceId': device_id, + }, + []) + self.EmitSignal(MAIN_IFACE, 'DeviceAdded', 'o', [device_path]) + return device_path + +@dbus.service.method(MAIN_IFACE, in_signature='o') +def DeleteDevice(self, device_path): + self.RemoveObject(device_path) + device_id = device_id_from_path(self, device_path) + del self.devices[device_id] + self.EmitSignal(MAIN_IFACE, 'DeviceRemoved', 'o', [device_path]) + + +@dbus.service.method(MAIN_IFACE, in_signature='s', out_signature='o') +def FindDeviceById(self, device_id): + return self.devices[device_id] + + +@dbus.service.method(MOCK_IFACE) +def ClearDevices(self): + for device_path in self.devices.values(): + self.RemoveObject(device_path) + self.devices = {} diff --git a/src/tests/meta-backend-test.c b/src/tests/meta-backend-test.c index 576990386..6916994e4 100644 --- a/src/tests/meta-backend-test.c +++ b/src/tests/meta-backend-test.c @@ -67,11 +67,6 @@ meta_backend_test_init_gpus (MetaBackendX11Nested *backend_x11_nested) meta_backend_add_gpu (META_BACKEND (backend_test), backend_test->gpu); } -static void -meta_backend_test_init (MetaBackendTest *backend_test) -{ -} - static MetaMonitorManager * meta_backend_test_create_monitor_manager (MetaBackend *backend, GError **error) @@ -175,6 +170,11 @@ meta_backend_test_remove_device (MetaBackendTest *backend_test, clutter_event_free (event); } +static void +meta_backend_test_init (MetaBackendTest *backend_test) +{ +} + static void meta_backend_test_class_init (MetaBackendTestClass *klass) { diff --git a/src/tests/meta-context-test.c b/src/tests/meta-context-test.c index 5a4e48876..f30070789 100644 --- a/src/tests/meta-context-test.c +++ b/src/tests/meta-context-test.c @@ -368,4 +368,30 @@ meta_context_test_class_init (MetaContextTestClass *klass) static void meta_context_test_init (MetaContextTest *context_test) { + GDBusProxy *proxy; + g_autoptr (GError) error = NULL; + g_autoptr (GVariant) ret = NULL; + + proxy = + g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, + NULL, + "org.freedesktop.ColorManager", + "/org/freedesktop/ColorManager", + "org.freedesktop.DBus.Mock", + NULL, &error); + if (!proxy) + { + g_warning ("Failed to find mocked color manager system service, %s", + error->message); + return; + } + + if (!g_dbus_proxy_call_sync (proxy, + "ClearDevices", + NULL, + G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, + &error)) + g_warning ("Failed to clear mocked color devices: %s", error->message); } diff --git a/src/tests/meta-dbus-runner.py b/src/tests/meta-dbus-runner.py index 512328c35..41dcdab2d 100755 --- a/src/tests/meta-dbus-runner.py +++ b/src/tests/meta-dbus-runner.py @@ -42,6 +42,7 @@ class MutterDBusTestCase(DBusTestCase): 'meta-mocks-manager', {'templates-dir': get_templates_dir()}) klass.start_from_local_template('localed') + klass.start_from_local_template('colord') klass.system_bus_con = klass.get_dbus(system_bus=True) klass.session_bus_con = klass.get_dbus(system_bus=False)