From a232d57d19c4a1befb4ae20708e64adc4e354f5f Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Wed, 4 Nov 2020 17:13:34 +0000
Subject: [PATCH] input-device test: Don't assert we can open devices that
 appear briefly

The portal device monitor won't be able to do this, because it loses
its record of which object path corresponds to which object as soon
as the device is removed.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 tests/input-device.c      |  4 ----
 tests/mock-input-device.c | 14 +++++++++-----
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/tests/input-device.c b/tests/input-device.c
index 659faeecb..f721a5916 100644
--- a/tests/input-device.c
+++ b/tests/input-device.c
@@ -2109,10 +2109,6 @@ device_added_cb (SrtInputDeviceMonitor *monitor,
 
       g_assert_cmphex (srt_input_device_get_type_flags (device), ==,
                        SRT_INPUT_DEVICE_TYPE_FLAGS_JOYSTICK);
-      g_assert_cmpuint (srt_input_device_get_interface_flags (device), ==,
-                        SRT_INPUT_DEVICE_INTERFACE_FLAGS_EVENT
-                        | SRT_INPUT_DEVICE_INTERFACE_FLAGS_READABLE
-                        | SRT_INPUT_DEVICE_INTERFACE_FLAGS_READ_WRITE);
 
       g_assert_cmphex (identity.bus_type, ==, BUS_USB);
       g_assert_cmphex (identity.vendor_id, ==, VENDOR_VALVE);
diff --git a/tests/mock-input-device.c b/tests/mock-input-device.c
index 123e411f7..a590dd27b 100644
--- a/tests/mock-input-device.c
+++ b/tests/mock-input-device.c
@@ -287,15 +287,19 @@ mock_input_device_monitor_remove (MockInputDeviceMonitor *self,
 static void
 add_steam_controller (MockInputDeviceMonitor *self,
                       const char *tail,
+                      gboolean can_open,
                       MockInputDevice **dev_out)
 {
   g_autoptr(MockInputDevice) mock = mock_input_device_new ();
   SrtSimpleInputDevice *device = SRT_SIMPLE_INPUT_DEVICE (mock);
   g_autoptr(GPtrArray) arr = g_ptr_array_new_full (1, g_free);
 
-  device->iface_flags = (SRT_INPUT_DEVICE_INTERFACE_FLAGS_EVENT
-                         | SRT_INPUT_DEVICE_INTERFACE_FLAGS_READABLE
-                         | SRT_INPUT_DEVICE_INTERFACE_FLAGS_READ_WRITE);
+  device->iface_flags = SRT_INPUT_DEVICE_INTERFACE_FLAGS_EVENT;
+
+  if (can_open)
+    device->iface_flags |= (SRT_INPUT_DEVICE_INTERFACE_FLAGS_READABLE
+                            | SRT_INPUT_DEVICE_INTERFACE_FLAGS_READ_WRITE);
+
   device->dev_node = g_strdup_printf ("/dev/input/event%s", tail);
   device->sys_path = g_strdup_printf ("/sys/devices/mock/usb/hid/input/input0/event%s",
                                       tail);
@@ -372,7 +376,7 @@ briefly_add_steam_controller_in_idle_cb (gpointer user_data)
   MockInputDeviceMonitor *self = MOCK_INPUT_DEVICE_MONITOR (user_data);
   g_autoptr(MockInputDevice) device = NULL;
 
-  add_steam_controller (self, "-connected-briefly", &device);
+  add_steam_controller (self, "-connected-briefly", FALSE, &device);
   mock_input_device_monitor_remove (self, device);
   return G_SOURCE_REMOVE;
 }
@@ -382,7 +386,7 @@ enumerate_cb (gpointer user_data)
 {
   MockInputDeviceMonitor *self = MOCK_INPUT_DEVICE_MONITOR (user_data);
 
-  add_steam_controller (self, "0", NULL);
+  add_steam_controller (self, "0", TRUE, NULL);
   _srt_input_device_monitor_emit_all_for_now (SRT_INPUT_DEVICE_MONITOR (self));
   return G_SOURCE_REMOVE;
 }
-- 
GitLab