File: test-keybindings.c

package info (click to toggle)
phoc 0.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,152 kB
  • sloc: ansic: 108,724; xml: 3,963; sh: 138; makefile: 33; javascript: 5
file content (58 lines) | stat: -rw-r--r-- 1,668 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 * Copyright (C) 2026 Phosh.mobi e.V.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * Author: Guido Günther <agx@sigxcpu.org>
 */

#include "keybindings.h"

#include <glib-object.h>


static void
test_keybindings_parse (void)
{
  g_autoptr (PhocKeybindingsContext) context = phoc_keybindings_context_new ();
  g_autoptr (PhocKeyCombo) combo = NULL;

  /* Simple case */
  combo = phoc_keybindings_parse_accelerator ("<shift>c", NULL);
  g_assert (combo);
  g_assert_cmpint (combo->modifiers, ==, WLR_MODIFIER_SHIFT);
  g_assert_cmpint (combo->keysym, ==, XKB_KEY_c);

  /* Using a capital letter doesn't affect the parsed keysym */
  g_free (combo);
  combo = phoc_keybindings_parse_accelerator ("<shift>C", NULL);
  g_assert (combo);
  g_assert_cmpint (combo->modifiers, ==, WLR_MODIFIER_SHIFT);
  g_assert_cmpint (combo->keysym, ==, XKB_KEY_c);

  /* Using a context doesn't affect the parsed keysym */
  g_free (combo);
  combo = phoc_keybindings_parse_accelerator ("<shift>c", context);
  g_assert (combo);
  g_assert_cmpint (combo->modifiers, ==, WLR_MODIFIER_SHIFT);
  g_assert_cmpint (combo->keysym, ==, XKB_KEY_c);

  /* The 'Above_Tab' accelerator keysym can be translated to a real keysym with the context */
  g_free (combo);
  context->above_tab_keysym = 0xa7;
  combo = phoc_keybindings_parse_accelerator ("<alt>Above_Tab", context);
  g_assert (combo);
  g_assert_cmpint (combo->modifiers, ==, WLR_MODIFIER_ALT);
  g_assert_cmpint (combo->keysym, ==, XKB_KEY_section);
}


int
main (int argc, char *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/phoc/keybindings/parse", test_keybindings_parse);

  return g_test_run ();
}