1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2012 Canonical Ltd
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
20
#include <gtest/gtest.h>
23
#include "KeyboardUtil.h"
25
using namespace unity::ui;
30
void test_key(KeyboardUtil const& key_util, Display* x_display, const char* key)
32
unsigned int above_keycode = key_util.GetKeycodeAboveKeySymbol(XStringToKeysym(key));
33
KeySym above_keysym = XkbKeycodeToKeysym(x_display, above_keycode, 0, 1);
34
EXPECT_NE(above_keysym, NoSymbol);
37
TEST(TestKeyboardUtil, AboveKeySymbol)
39
Display* x_display = XOpenDisplay(NULL);
41
KeyboardUtil key_util(x_display);
42
test_key(key_util, x_display, "Tab");
43
test_key(key_util, x_display, "Shift_R");
44
test_key(key_util, x_display, "Control_L");
45
test_key(key_util, x_display, "space");
46
test_key(key_util, x_display, "comma");
47
test_key(key_util, x_display, "a");
48
test_key(key_util, x_display, "b");
49
test_key(key_util, x_display, "c");
50
test_key(key_util, x_display, "d");
51
test_key(key_util, x_display, "e");
52
test_key(key_util, x_display, "f");
53
test_key(key_util, x_display, "g");
54
test_key(key_util, x_display, "h");
55
test_key(key_util, x_display, "i");
56
test_key(key_util, x_display, "j");
57
test_key(key_util, x_display, "k");
58
test_key(key_util, x_display, "l");
59
test_key(key_util, x_display, "m");
60
test_key(key_util, x_display, "n");
61
test_key(key_util, x_display, "o");
62
test_key(key_util, x_display, "p");
63
test_key(key_util, x_display, "k");
64
test_key(key_util, x_display, "r");
65
test_key(key_util, x_display, "s");
66
test_key(key_util, x_display, "t");
67
test_key(key_util, x_display, "u");
68
test_key(key_util, x_display, "v");
69
test_key(key_util, x_display, "w");
70
test_key(key_util, x_display, "x");
71
test_key(key_util, x_display, "y");
72
test_key(key_util, x_display, "z");
75
TEST(TestKeyboardUtil, PrintableKeySymbols)
77
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_Delete));
78
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_BackSpace));
79
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_space));
80
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_3));
81
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_v));
82
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_1));
83
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_ntilde));
84
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_0));
85
EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_exclam));
87
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_F1));
88
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Select));
89
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Hyper_R));
90
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Control_L));
91
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Shift_L));
92
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Super_L));
93
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Print));
94
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Insert));
95
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Num_Lock));
96
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Caps_Lock));
97
EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_ISO_Level3_Shift));
100
TEST(TestKeyboardUtil, MoveKeySymbols)
102
std::vector<KeySym> move_symbols { XK_Home, XK_Left, XK_Up, XK_Right, XK_Down,
103
XK_Prior, XK_Page_Up, XK_Next, XK_Page_Down,
106
for (KeySym sym = 0; sym < XK_VoidSymbol; ++sym)
108
if (std::find(move_symbols.begin(), move_symbols.end(), sym) != move_symbols.end())
109
EXPECT_TRUE(KeyboardUtil::IsMoveKeySymbol(sym));
111
EXPECT_FALSE(KeyboardUtil::IsMoveKeySymbol(sym));