Back to index

unity  6.0.0
test_keyboard_util.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2012 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Marco Trevisan (TreviƱo) <3v1n0@ubuntu.com>
00018  */
00019 
00020 #include <gtest/gtest.h>
00021 #include <algorithm>
00022 
00023 #include "KeyboardUtil.h"
00024 
00025 using namespace unity::ui;
00026 
00027 namespace
00028 {
00029 
00030 void test_key(KeyboardUtil const& key_util, Display* x_display, const char* key)
00031 {
00032   unsigned int above_keycode = key_util.GetKeycodeAboveKeySymbol(XStringToKeysym(key));
00033   KeySym above_keysym = XkbKeycodeToKeysym(x_display, above_keycode, 0, 1);
00034   EXPECT_NE(above_keysym, NoSymbol);
00035 }
00036 
00037 TEST(TestKeyboardUtil, AboveKeySymbol)
00038 {
00039   Display* x_display = XOpenDisplay(NULL);
00040 
00041   KeyboardUtil key_util(x_display);
00042   test_key(key_util, x_display, "Tab");
00043   test_key(key_util, x_display, "Shift_R");
00044   test_key(key_util, x_display, "Control_L");
00045   test_key(key_util, x_display, "space");
00046   test_key(key_util, x_display, "comma");
00047   test_key(key_util, x_display, "a");
00048   test_key(key_util, x_display, "b");
00049   test_key(key_util, x_display, "c");
00050   test_key(key_util, x_display, "d");
00051   test_key(key_util, x_display, "e");
00052   test_key(key_util, x_display, "f");
00053   test_key(key_util, x_display, "g");
00054   test_key(key_util, x_display, "h");
00055   test_key(key_util, x_display, "i");
00056   test_key(key_util, x_display, "j");
00057   test_key(key_util, x_display, "k");
00058   test_key(key_util, x_display, "l");
00059   test_key(key_util, x_display, "m");
00060   test_key(key_util, x_display, "n");
00061   test_key(key_util, x_display, "o");
00062   test_key(key_util, x_display, "p");
00063   test_key(key_util, x_display, "k");
00064   test_key(key_util, x_display, "r");
00065   test_key(key_util, x_display, "s");
00066   test_key(key_util, x_display, "t");
00067   test_key(key_util, x_display, "u");
00068   test_key(key_util, x_display, "v");
00069   test_key(key_util, x_display, "w");
00070   test_key(key_util, x_display, "x");
00071   test_key(key_util, x_display, "y");
00072   test_key(key_util, x_display, "z");
00073 }
00074 
00075 TEST(TestKeyboardUtil, PrintableKeySymbols)
00076 {
00077   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_Delete));
00078   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_BackSpace));
00079   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_space));
00080   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_3));
00081   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_v));
00082   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_1));
00083   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_ntilde));
00084   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_0));
00085   EXPECT_TRUE(KeyboardUtil::IsPrintableKeySymbol(XK_exclam));
00086 
00087   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_F1));
00088   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Select));
00089   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Hyper_R));
00090   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Control_L));
00091   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Shift_L));
00092   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Super_L));
00093   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Print));
00094   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Insert));
00095   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Num_Lock));
00096   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_Caps_Lock));
00097   EXPECT_FALSE(KeyboardUtil::IsPrintableKeySymbol(XK_ISO_Level3_Shift));
00098 }
00099 
00100 TEST(TestKeyboardUtil, MoveKeySymbols)
00101 {
00102   std::vector<KeySym> move_symbols { XK_Home, XK_Left, XK_Up, XK_Right, XK_Down,
00103                                      XK_Prior, XK_Page_Up, XK_Next, XK_Page_Down,
00104                                      XK_End, XK_Begin };
00105 
00106   for (KeySym sym = 0; sym < XK_VoidSymbol; ++sym)
00107   {
00108     if (std::find(move_symbols.begin(), move_symbols.end(), sym) != move_symbols.end())
00109       EXPECT_TRUE(KeyboardUtil::IsMoveKeySymbol(sym));
00110     else
00111       EXPECT_FALSE(KeyboardUtil::IsMoveKeySymbol(sym));
00112   }
00113 }
00114 
00115 } // Namespace