From aa4bb1dee404cbcd6f378ef1b225177f772ea4b4 Mon Sep 17 00:00:00 2001 From: Andy Holmes Date: Mon, 22 Dec 2025 06:56:13 -0800 Subject: [PATCH 1/2] test(mousepad): iterate all specialKeys --- src/plugins/mousepad/valent-mousepad-plugin.c | 3 ++ tests/plugins/mousepad/test-mousepad-plugin.c | 49 ++++++++++--------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/plugins/mousepad/valent-mousepad-plugin.c b/src/plugins/mousepad/valent-mousepad-plugin.c index df25a442db1..f230d9d8d4c 100644 --- a/src/plugins/mousepad/valent-mousepad-plugin.c +++ b/src/plugins/mousepad/valent-mousepad-plugin.c @@ -340,6 +340,9 @@ valent_mousepad_plugin_mousepad_request_keyboard (ValentMousepadPlugin *self, g_assert (VALENT_IS_MOUSEPAD_PLUGIN (self)); + if G_UNLIKELY (keysym == 0 && mask == 0) + return; + valent_packet_init (&builder, "kdeconnect.mousepad.request"); if ((special_key = valent_mousepad_keysym_to_keycode (keysym)) != 0) diff --git a/tests/plugins/mousepad/test-mousepad-plugin.c b/tests/plugins/mousepad/test-mousepad-plugin.c index 5c1218f0695..994dfc5c656 100644 --- a/tests/plugins/mousepad/test-mousepad-plugin.c +++ b/tests/plugins/mousepad/test-mousepad-plugin.c @@ -186,6 +186,9 @@ test_mousepad_plugin_send_keyboard_request (ValentTestFixture *fixture, { GActionGroup *actions = G_ACTION_GROUP (fixture->device); JsonNode *packet; + uint32_t keysym; + unsigned int mask; + gunichar *w; GVariantDict dict; gboolean watch = FALSE; @@ -213,10 +216,6 @@ test_mousepad_plugin_send_keyboard_request (ValentTestFixture *fixture, g_assert_true (g_action_group_get_action_enabled (actions, "mousepad.event")); VALENT_TEST_CHECK ("Plugin action `mousepad.event` sends ASCII with modifiers"); - uint32_t keysym; - unsigned int mask; - gunichar *w; - keysym = 'a'; mask = KEYMOD_KDE_MASK; @@ -258,24 +257,30 @@ test_mousepad_plugin_send_keyboard_request (ValentTestFixture *fixture, VALENT_TEST_CHECK ("Plugin action `mousepad.event` sends special keys " "(aka non-printable ASCII"); - // TODO iterate special keys - keysym = KEYSYM_F12; - mask = 0; - - g_variant_dict_init (&dict, NULL); - g_variant_dict_insert (&dict, "keysym", "u", keysym); - g_variant_dict_insert (&dict, "mask", "u", mask); - g_action_group_activate_action (actions, "mousepad.event", - g_variant_dict_end (&dict)); - - packet = valent_test_fixture_expect_packet (fixture); - v_assert_packet_type (packet, "kdeconnect.mousepad.request"); - v_assert_packet_cmpint (packet, "specialKey", ==, 32); - v_assert_packet_no_field (packet, "alt"); - v_assert_packet_no_field (packet, "ctrl"); - v_assert_packet_no_field (packet, "shift"); - v_assert_packet_no_field (packet, "super"); - json_node_unref (packet); + for (size_t i = 1; i < 33; i++) + { + keysym = valent_mousepad_keycode_to_keysym (i); + mask = 0; + + g_variant_dict_init (&dict, NULL); + g_variant_dict_insert (&dict, "keysym", "u", keysym); + g_variant_dict_insert (&dict, "mask", "u", mask); + g_action_group_activate_action (actions, "mousepad.event", + g_variant_dict_end (&dict)); + + // Reserved keycodes should be skipped + if (keysym == 0) + continue; + + packet = valent_test_fixture_expect_packet (fixture); + v_assert_packet_type (packet, "kdeconnect.mousepad.request"); + v_assert_packet_cmpint (packet, "specialKey", ==, i); + v_assert_packet_no_field (packet, "alt"); + v_assert_packet_no_field (packet, "ctrl"); + v_assert_packet_no_field (packet, "shift"); + v_assert_packet_no_field (packet, "super"); + json_node_unref (packet); + } valent_test_watch_clear (actions, &watch); } From 3d6f8c5e0bca594b28510027d67bac61bd618f20 Mon Sep 17 00:00:00 2001 From: Andy Holmes Date: Mon, 22 Dec 2025 07:16:45 -0800 Subject: [PATCH 2/2] test(mouspad): slight improvements to compose tests --- tests/fixtures/data/plugin-mousepad.json | 9 +++- tests/plugins/mousepad/test-mousepad-plugin.c | 53 +++++++++++++++---- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/tests/fixtures/data/plugin-mousepad.json b/tests/fixtures/data/plugin-mousepad.json index 3be947dafe8..ab553083c5a 100644 --- a/tests/fixtures/data/plugin-mousepad.json +++ b/tests/fixtures/data/plugin-mousepad.json @@ -149,7 +149,14 @@ "id": 0, "type": "kdeconnect.mousepad.request", "body": { - "key": "test" + "key": "The quick brown fox jumps over the lazy dog" + } + }, + "keyboard-keysym-unicode": { + "id": 0, + "type": "kdeconnect.mousepad.request", + "body": { + "key": "A©∑𝜑🚀" } } } diff --git a/tests/plugins/mousepad/test-mousepad-plugin.c b/tests/plugins/mousepad/test-mousepad-plugin.c index 994dfc5c656..1a3312ac676 100644 --- a/tests/plugins/mousepad/test-mousepad-plugin.c +++ b/tests/plugins/mousepad/test-mousepad-plugin.c @@ -17,6 +17,34 @@ static GQueue events = G_QUEUE_INIT; g_free (_event_str); \ } G_STMT_END +static void +_valent_test_event_cmpstrv (const char *str) +{ + const char *next = str; + gunichar codepoint; + + while ((codepoint = g_utf8_get_char (next)) != 0) + { + uint32_t keysym = valent_input_unicode_to_keysym (codepoint); + char *event_str = NULL; + char *expected_str = NULL; + + event_str = g_queue_pop_head (&events); + expected_str = g_strdup_printf ("KEYSYM %u 1", keysym); + g_assert_cmpstr (event_str, ==, expected_str); + g_free (event_str); + g_free (expected_str); + + event_str = g_queue_pop_head (&events); + expected_str = g_strdup_printf ("KEYSYM %u 0", keysym); + g_assert_cmpstr (event_str, ==, expected_str); + g_free (event_str); + g_free (expected_str); + + next = g_utf8_next_char (next); + } +} + static void on_event_state_changed (GActionGroup *group, const char *name, @@ -74,6 +102,7 @@ test_mousepad_plugin_handle_request (ValentTestFixture *fixture, gconstpointer user_data) { JsonNode *packet; + const char *str; VALENT_TEST_CHECK ("Plugin sends the keyboard state on connect"); valent_test_fixture_connect (fixture); @@ -166,18 +195,20 @@ test_mousepad_plugin_handle_request (ValentTestFixture *fixture, _valent_test_event_cmpstr ("KEYSYM 65361 1"); _valent_test_event_cmpstr ("KEYSYM 65361 0"); - VALENT_TEST_CHECK ("Plugin handles a request to press-release a series of keysyms"); - packet = valent_test_fixture_lookup_packet (fixture, "keyboard-keysym-string"); - valent_test_fixture_handle_packet (fixture, packet); + static const char *keysym_tests[] = { + "keyboard-keysym-string", + "keyboard-keysym-unicode", + }; - _valent_test_event_cmpstr ("KEYSYM 116 1"); - _valent_test_event_cmpstr ("KEYSYM 116 0"); - _valent_test_event_cmpstr ("KEYSYM 101 1"); - _valent_test_event_cmpstr ("KEYSYM 101 0"); - _valent_test_event_cmpstr ("KEYSYM 115 1"); - _valent_test_event_cmpstr ("KEYSYM 115 0"); - _valent_test_event_cmpstr ("KEYSYM 116 1"); - _valent_test_event_cmpstr ("KEYSYM 116 0"); + for (size_t i = 0; i < G_N_ELEMENTS (keysym_tests); i++) + { + VALENT_TEST_CHECK ("Plugin handles a request to press-release a series of keysyms"); + packet = valent_test_fixture_lookup_packet (fixture, keysym_tests[i]); + valent_test_fixture_handle_packet (fixture, packet); + + valent_packet_get_string (packet, "key", &str); + _valent_test_event_cmpstrv (str); + } } static void