2011-11-03 18:53:19 +00:00
|
|
|
|
/* accel.c - test accel parsing
|
|
|
|
|
* Copyright (C) 2011 Bastien Nocera <hadess@hadess.net>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-11-03 18:53:19 +00:00
|
|
|
|
*/
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <locale.h>
|
|
|
|
|
|
|
|
|
|
static void
|
2020-04-05 23:52:25 +00:00
|
|
|
|
test_one_accel (const char *accel,
|
|
|
|
|
GdkModifierType exp_mods,
|
|
|
|
|
guint exp_key,
|
|
|
|
|
const char *exp_label,
|
|
|
|
|
gboolean has_keysym)
|
2011-11-03 18:53:19 +00:00
|
|
|
|
{
|
|
|
|
|
guint accel_key;
|
|
|
|
|
GdkModifierType mods;
|
|
|
|
|
guint *keycodes;
|
|
|
|
|
char *label, *name;
|
|
|
|
|
|
2011-11-10 10:59:44 +00:00
|
|
|
|
accel_key = 0;
|
2018-08-20 17:45:51 +00:00
|
|
|
|
g_assert (gtk_accelerator_parse_with_keycode (accel,
|
2018-08-20 22:44:47 +00:00
|
|
|
|
gdk_display_get_default (),
|
2018-08-20 17:45:51 +00:00
|
|
|
|
&accel_key,
|
|
|
|
|
&keycodes,
|
|
|
|
|
&mods));
|
2011-11-03 18:53:19 +00:00
|
|
|
|
|
2011-11-16 16:13:01 +00:00
|
|
|
|
if (has_keysym)
|
|
|
|
|
{
|
|
|
|
|
guint accel_key_2;
|
|
|
|
|
GdkModifierType mods_2;
|
|
|
|
|
|
2018-08-20 17:45:51 +00:00
|
|
|
|
g_assert (gtk_accelerator_parse (accel,
|
|
|
|
|
&accel_key_2,
|
|
|
|
|
&mods_2));
|
2011-11-16 16:13:01 +00:00
|
|
|
|
g_assert (accel_key == accel_key_2);
|
|
|
|
|
g_assert (mods == mods_2);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-10 10:59:44 +00:00
|
|
|
|
if (has_keysym)
|
2020-04-05 23:52:25 +00:00
|
|
|
|
g_assert (accel_key == exp_key);
|
|
|
|
|
g_assert (mods == exp_mods);
|
2011-11-03 18:53:19 +00:00
|
|
|
|
g_assert (keycodes);
|
|
|
|
|
g_assert (keycodes[0] != 0);
|
|
|
|
|
|
|
|
|
|
label = gtk_accelerator_get_label_with_keycode (NULL,
|
|
|
|
|
accel_key,
|
|
|
|
|
*keycodes,
|
|
|
|
|
mods);
|
|
|
|
|
|
|
|
|
|
g_assert_cmpstr (label, ==, exp_label);
|
|
|
|
|
|
|
|
|
|
name = gtk_accelerator_name_with_keycode (NULL,
|
|
|
|
|
accel_key,
|
|
|
|
|
*keycodes,
|
|
|
|
|
mods);
|
|
|
|
|
g_assert_cmpstr (name, ==, accel);
|
|
|
|
|
|
|
|
|
|
g_free (keycodes);
|
|
|
|
|
g_free (label);
|
|
|
|
|
g_free (name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-11-16 18:49:54 +00:00
|
|
|
|
accel1 (void)
|
2011-11-03 18:53:19 +00:00
|
|
|
|
{
|
2020-04-05 23:52:25 +00:00
|
|
|
|
test_one_accel ("0xb3", 0, 0xb3, "0xb3", FALSE);
|
2011-11-16 18:49:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
accel2 (void)
|
|
|
|
|
{
|
2020-04-05 23:52:25 +00:00
|
|
|
|
test_one_accel ("<Control><Alt>z", GDK_CONTROL_MASK|GDK_ALT_MASK, GDK_KEY_z, "Ctrl+Alt+Z", TRUE);
|
2011-11-03 18:53:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-16 18:49:54 +00:00
|
|
|
|
static void
|
|
|
|
|
accel3 (void)
|
|
|
|
|
{
|
2020-05-21 22:05:43 +00:00
|
|
|
|
test_one_accel ("KP_7", 0, GDK_KEY_KP_7, "KP 7", TRUE);
|
2011-11-16 18:49:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
accel4 (void)
|
|
|
|
|
{
|
2020-05-21 22:05:43 +00:00
|
|
|
|
test_one_accel ("<Control>KP_7", GDK_CONTROL_MASK, GDK_KEY_KP_7, "Ctrl+KP 7", TRUE);
|
2011-11-16 18:49:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
accel5 (void)
|
|
|
|
|
{
|
2020-04-05 23:52:25 +00:00
|
|
|
|
test_one_accel ("<Shift>exclam", GDK_SHIFT_MASK, GDK_KEY_exclam, "Shift+!", TRUE);
|
2011-11-16 18:49:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-17 05:54:43 +00:00
|
|
|
|
static void
|
|
|
|
|
accel6 (void)
|
|
|
|
|
{
|
2020-04-05 23:52:25 +00:00
|
|
|
|
test_one_accel ("<Hyper>x", GDK_HYPER_MASK, GDK_KEY_x, "Hyper+X", TRUE);
|
2016-04-17 05:54:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
accel7 (void)
|
|
|
|
|
{
|
2020-04-05 23:52:25 +00:00
|
|
|
|
test_one_accel ("<Super>x", GDK_SUPER_MASK, GDK_KEY_x, "Super+X", TRUE);
|
2016-04-17 05:54:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
accel8 (void)
|
|
|
|
|
{
|
2020-04-05 23:52:25 +00:00
|
|
|
|
test_one_accel ("<Meta>x", GDK_META_MASK, GDK_KEY_x, "Meta+X", TRUE);
|
2016-04-17 05:54:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-16 18:49:54 +00:00
|
|
|
|
static void
|
|
|
|
|
keysyms (void)
|
|
|
|
|
{
|
|
|
|
|
g_assert (gdk_keyval_from_name ("KP_7") == GDK_KEY_KP_7);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-03 18:53:19 +00:00
|
|
|
|
int
|
|
|
|
|
main (int argc,
|
|
|
|
|
char *argv[])
|
|
|
|
|
{
|
|
|
|
|
setlocale (LC_ALL, "en_GB.UTF-8");
|
|
|
|
|
|
|
|
|
|
gtk_test_init (&argc, &argv);
|
2011-11-16 18:49:54 +00:00
|
|
|
|
|
|
|
|
|
g_test_add_func ("/keysyms", keysyms);
|
|
|
|
|
|
|
|
|
|
g_test_add_func ("/accel1", accel1);
|
|
|
|
|
g_test_add_func ("/accel2", accel2);
|
|
|
|
|
g_test_add_func ("/accel3", accel3);
|
|
|
|
|
g_test_add_func ("/accel4", accel4);
|
|
|
|
|
g_test_add_func ("/accel5", accel5);
|
2016-04-17 05:54:43 +00:00
|
|
|
|
g_test_add_func ("/accel6", accel6);
|
|
|
|
|
g_test_add_func ("/accel7", accel7);
|
|
|
|
|
g_test_add_func ("/accel8", accel8);
|
|
|
|
|
|
2011-11-03 18:53:19 +00:00
|
|
|
|
return g_test_run();
|
|
|
|
|
}
|