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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/* 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
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
#include <locale.h>
static void
test_one_accel (const char *accel,
GdkModifierType exp_mods,
guint exp_key,
const char *exp_label,
gboolean has_keysym)
{
guint accel_key;
GdkModifierType mods;
guint *keycodes;
char *label, *name;
gboolean ret;
accel_key = 0;
ret = gtk_accelerator_parse_with_keycode (accel,
gdk_display_get_default (),
&accel_key,
&keycodes,
&mods);
g_assert_true (ret);
if (has_keysym)
{
guint accel_key_2;
GdkModifierType mods_2;
ret = gtk_accelerator_parse (accel, &accel_key_2, &mods_2);
g_assert_true (ret);
g_assert_true (accel_key == accel_key_2);
g_assert_true (mods == mods_2);
}
if (has_keysym)
g_assert_true (accel_key == exp_key);
g_assert_true (mods == exp_mods);
g_assert_nonnull (keycodes);
g_assert_true (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
accel1 (void)
{
test_one_accel ("0xb3", 0, 0xb3, "0xb3", FALSE);
}
static void
accel2 (void)
{
test_one_accel ("<Control><Alt>z", GDK_CONTROL_MASK|GDK_ALT_MASK, GDK_KEY_z, "Ctrl+Alt+Z", TRUE);
}
static void
accel3 (void)
{
test_one_accel ("KP_7", 0, GDK_KEY_KP_7, "KP 7", TRUE);
}
static void
accel4 (void)
{
test_one_accel ("<Control>KP_7", GDK_CONTROL_MASK, GDK_KEY_KP_7, "Ctrl+KP 7", TRUE);
}
static void
accel5 (void)
{
test_one_accel ("<Shift>exclam", GDK_SHIFT_MASK, GDK_KEY_exclam, "Shift+!", TRUE);
}
static void
accel6 (void)
{
test_one_accel ("<Hyper>x", GDK_HYPER_MASK, GDK_KEY_x, "Hyper+X", TRUE);
}
static void
accel7 (void)
{
test_one_accel ("<Super>x", GDK_SUPER_MASK, GDK_KEY_x, "Super+X", TRUE);
}
static void
accel8 (void)
{
test_one_accel ("<Meta>x", GDK_META_MASK, GDK_KEY_x, "Meta+X", TRUE);
}
static void
keysyms (void)
{
g_assert_cmpuint (gdk_keyval_from_name ("KP_7"), ==, GDK_KEY_KP_7);
}
int
main (int argc,
char *argv[])
{
setlocale (LC_ALL, "en_GB.UTF-8");
gtk_test_init (&argc, &argv);
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);
g_test_add_func ("/accel6", accel6);
g_test_add_func ("/accel7", accel7);
g_test_add_func ("/accel8", accel8);
return g_test_run();
}
|