[mutter] tests/mock/colord: Add profile mock support



commit 60d0394468f629000052a1929e77953dea870485
Author: Jonas Ã…dahl <jadahl gmail com>
Date:   Tue Nov 30 11:58:08 2021 +0100

    tests/mock/colord: Add profile mock support
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2164>

 src/tests/dbusmock-templates/colord.py | 42 +++++++++++++++++++++++++++++++++-
 src/tests/meta-context-test.c          |  2 +-
 2 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/src/tests/dbusmock-templates/colord.py b/src/tests/dbusmock-templates/colord.py
index c3901dbbd3..d1912af445 100644
--- a/src/tests/dbusmock-templates/colord.py
+++ b/src/tests/dbusmock-templates/colord.py
@@ -23,11 +23,13 @@ BUS_NAME = BUS_PREFIX
 MAIN_OBJ = PATH_PREFIX
 MAIN_IFACE = BUS_NAME
 DEVICE_IFACE = BUS_PREFIX + '.Device'
+PROFILE_IFACE = BUS_PREFIX + '.Profile'
 SYSTEM_BUS = True
 
 
 def load(mock, parameters=None):
     mock.devices = {}
+    mock.profiles = {}
 
 def escape_unit_name(name):
     for s in ['.', '-', '\'', ' ']:
@@ -44,6 +46,13 @@ def device_id_from_path(mock, path):
             return device_id
     return None
 
+def profile_id_from_path(mock, path):
+  for profile_id in mock.profiles:
+     profile_path = mock.profiles[profile_id]
+     if profile_path == path:
+         return profile_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()
@@ -56,6 +65,7 @@ def CreateDevice(self, device_id, scope, props):
                    DEVICE_IFACE,
                    {
                      'DeviceId': device_id,
+                     'Enabled': True,
                    },
                    [])
     self.EmitSignal(MAIN_IFACE, 'DeviceAdded', 'o', [device_path])
@@ -74,8 +84,38 @@ def FindDeviceById(self, device_id):
     return self.devices[device_id]
 
 
+@dbus.service.method(MAIN_IFACE, in_signature='ssha{sv}', out_signature='o')
+def CreateProfileWithFd(self, profile_id, scope, handle, props):
+    uid = os.getuid()
+    username = get_username(uid)
+    profile_path = PATH_PREFIX + '/profiles/' + \
+        escape_unit_name(profile_id) + \
+        '_' + username + '_' + str(uid)
+    self.profiles[profile_id] = profile_path
+    self.AddObject(profile_path,
+                   PROFILE_IFACE,
+                   {
+                     'ProfileId': profile_id,
+                     'Enabled': True,
+                     'Filename': props['Filename'],
+                   },
+                   [])
+    self.EmitSignal(MAIN_IFACE, 'ProfileAdded', 'o', [profile_path])
+    return profile_path
+
+@dbus.service.method(MAIN_IFACE, in_signature='o')
+def DeleteProfile(self, profile_path):
+    self.RemoveObject(profile_path)
+    profile_id = profile_id_from_path(self, profile_path)
+    del self.profiles[profile_id]
+    self.EmitSignal(MAIN_IFACE, 'ProfileRemoved', 'o', [profile_path])
+
+
 @dbus.service.method(MOCK_IFACE)
-def ClearDevices(self):
+def Reset(self):
     for device_path in self.devices.values():
         self.RemoveObject(device_path)
     self.devices = {}
+    for profile_path in self.profiles.values():
+        self.RemoveObject(profile_path)
+    self.profiles = {}
diff --git a/src/tests/meta-context-test.c b/src/tests/meta-context-test.c
index f30070789f..7d609dad37 100644
--- a/src/tests/meta-context-test.c
+++ b/src/tests/meta-context-test.c
@@ -389,7 +389,7 @@ meta_context_test_init (MetaContextTest *context_test)
     }
 
   if (!g_dbus_proxy_call_sync (proxy,
-                               "ClearDevices",
+                               "Reset",
                                NULL,
                                G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL,
                                &error))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]