From: Simon Glass <sjg@chromium.org>
Add a test for the mouse set_ptr_visible() method. This uses a back-door
function to read the visibility state from the sandbox mouse driver.
Also add documentation for struct sandbox_mouse_priv.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
arch/sandbox/include/asm/test.h | 8 ++++++++
drivers/input/sandbox_mouse.c | 25 +++++++++++++++++++++++++
test/dm/mouse.c | 22 ++++++++++++++++++++++
3 files changed, 55 insertions(+)
@@ -378,4 +378,12 @@ void sandbox_mouse_set_test_mode(struct udevice *dev, bool test_mode);
*/
void sandbox_mouse_inject(struct udevice *dev, struct mouse_event *event);
+/**
+ * sandbox_mouse_get_ptr_visible() - Get pointer visibility state
+ *
+ * @dev: Mouse device
+ * Return: true if pointer is visible, false if hidden
+ */
+bool sandbox_mouse_get_ptr_visible(struct udevice *dev);
+
#endif
@@ -8,10 +8,19 @@
#include <mouse.h>
#include <asm/sdl.h>
+/**
+ * struct sandbox_mouse_priv - Private data for sandbox mouse driver
+ *
+ * @test_mode: true to use test mode (inject events), false to use SDL
+ * @test_event: Event to return when in test mode
+ * @test_event_pending: true if test_event is pending
+ * @ptr_visible: Current visibility state of mouse pointer
+ */
struct sandbox_mouse_priv {
bool test_mode;
struct mouse_event test_event;
bool test_event_pending;
+ bool ptr_visible;
};
static int mouse_sandbox_get_event(struct udevice *dev,
@@ -38,6 +47,9 @@ static int mouse_sandbox_get_event(struct udevice *dev,
static int mouse_sandbox_set_ptr_visible(struct udevice *dev, bool visible)
{
+ struct sandbox_mouse_priv *priv = dev_get_priv(dev);
+
+ priv->ptr_visible = visible;
sandbox_sdl_set_cursor_visible(visible);
return 0;
@@ -83,6 +95,19 @@ void sandbox_mouse_inject(struct udevice *dev, struct mouse_event *event)
}
}
+/**
+ * sandbox_mouse_get_ptr_visible() - Get pointer visibility state
+ *
+ * @dev: Mouse device
+ * Return: true if pointer is visible, false if hidden
+ */
+bool sandbox_mouse_get_ptr_visible(struct udevice *dev)
+{
+ struct sandbox_mouse_priv *priv = dev_get_priv(dev);
+
+ return priv->ptr_visible;
+}
+
U_BOOT_DRIVER(mouse_sandbox) = {
.name = "mouse_sandbox",
.id = UCLASS_MOUSE,
@@ -214,3 +214,25 @@ static int dm_test_mouse_right_button(struct unit_test_state *uts)
return 0;
}
DM_TEST(dm_test_mouse_right_button, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+static int dm_test_mouse_ptr_visible(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ ut_assertok(uclass_first_device_err(UCLASS_MOUSE, &dev));
+
+ /* test hiding the pointer */
+ ut_assertok(mouse_set_ptr_visible(dev, false));
+ ut_asserteq(false, sandbox_mouse_get_ptr_visible(dev));
+
+ /* test showing the pointer */
+ ut_assertok(mouse_set_ptr_visible(dev, true));
+ ut_asserteq(true, sandbox_mouse_get_ptr_visible(dev));
+
+ /* test hiding again */
+ ut_assertok(mouse_set_ptr_visible(dev, false));
+ ut_asserteq(false, sandbox_mouse_get_ptr_visible(dev));
+
+ return 0;
+}
+DM_TEST(dm_test_mouse_ptr_visible, UTF_SCAN_PDATA | UTF_SCAN_FDT);