Back to index

nux  3.0.0
gtest-nux-inputmethodibus.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Inalogic Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as published
00006  * by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * version 3 along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>
00016  *
00017  * Authored by: Marco Trevisan <marco.trevisan@canonical.com>
00018  *
00019  */
00020 
00021 #include <gmock/gmock.h>
00022 
00023 #include "Nux/Nux.h"
00024 #include "Nux/InputMethodIBus.h"
00025 
00026 
00027 using namespace nux;
00028 
00029 class MockIBusIMEContext : public IBusIMEContext
00030 {
00031 public:
00032   static std::vector<Event> ParseIBusHotkeys(const gchar** keybindings)
00033   {
00034     return IBusIMEContext::ParseIBusHotkeys(keybindings);
00035   }
00036 };
00037 
00038 namespace {
00039 
00040 TEST(TestIBusIMEContext, ParseNullHotkeys)
00041 {
00042   auto hotkeys = MockIBusIMEContext::ParseIBusHotkeys(nullptr);
00043   EXPECT_TRUE(hotkeys.empty());
00044 }
00045 
00046 TEST(TestIBusIMEContext, ParseInvalidHotkeys)
00047 {
00048   const gchar* invalid_code[] = {"Alt+InvalidCode", nullptr };
00049 
00050   auto hotkeys = MockIBusIMEContext::ParseIBusHotkeys(invalid_code);
00051   EXPECT_TRUE(hotkeys.empty());
00052 
00053 
00054   const gchar* missing_key[] = {"Alt+Control", nullptr };
00055 
00056   hotkeys = MockIBusIMEContext::ParseIBusHotkeys(missing_key);
00057   EXPECT_TRUE(hotkeys.empty());
00058 }
00059 
00060 TEST(TestIBusIMEContext, ParseHotkeys)
00061 {
00062   const gchar* keybindings[] = {"Control+space", "Zenkaku_Hankaku", "Alt+Kanji",
00063                                 "Alt+grave", "Hangul", "Alt+Release+Alt_R",
00064                                 "Alt+Control+Release+Shift_L", nullptr};
00065 
00066   auto hotkeys = MockIBusIMEContext::ParseIBusHotkeys(keybindings);
00067   ASSERT_EQ(hotkeys.size(), 7);
00068 
00069   auto event = hotkeys[0];
00070   EXPECT_EQ(event.type, NUX_KEYDOWN);
00071   EXPECT_EQ(event.key_modifiers, KEY_MODIFIER_CTRL);
00072   EXPECT_EQ(event.x11_keysym, XK_space);
00073 
00074   event = hotkeys[1];
00075   EXPECT_EQ(event.type, NUX_KEYDOWN);
00076   EXPECT_EQ(event.key_modifiers, 0);
00077   EXPECT_EQ(event.x11_keysym, XK_Zenkaku_Hankaku);
00078 
00079   event = hotkeys[2];
00080   EXPECT_EQ(event.type, NUX_KEYDOWN);
00081   EXPECT_EQ(event.key_modifiers, KEY_MODIFIER_ALT);
00082   EXPECT_EQ(event.x11_keysym, XK_Kanji);
00083 
00084   event = hotkeys[3];
00085   EXPECT_EQ(event.type, NUX_KEYDOWN);
00086   EXPECT_EQ(event.key_modifiers, KEY_MODIFIER_ALT);
00087   EXPECT_EQ(event.x11_keysym, XK_grave);
00088 
00089   event = hotkeys[4];
00090   EXPECT_EQ(event.type, NUX_KEYDOWN);
00091   EXPECT_EQ(event.key_modifiers, 0);
00092   EXPECT_EQ(event.x11_keysym, XK_Hangul);
00093 
00094   event = hotkeys[5];
00095   EXPECT_EQ(event.type, NUX_KEYUP);
00096   EXPECT_EQ(event.key_modifiers, KEY_MODIFIER_ALT);
00097   EXPECT_EQ(event.x11_keysym, XK_Alt_R);
00098 
00099   event = hotkeys[6];
00100   EXPECT_EQ(event.type, NUX_KEYUP);
00101   EXPECT_EQ(event.key_modifiers, (KEY_MODIFIER_ALT | KEY_MODIFIER_CTRL));
00102   EXPECT_EQ(event.x11_keysym, XK_Shift_L);
00103 }
00104 
00105 }