| 1 |
/* |
| 2 |
* Copyright (C) 2024 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "ServiceBroker.h" |
| 10 |
#include "addons/AddonManager.h" |
| 11 |
#include "addons/addoninfo/AddonType.h" |
| 12 |
#include "games/controllers/Controller.h" |
| 13 |
#include "games/controllers/ControllerIDs.h" |
| 14 |
#include "games/controllers/input/PhysicalFeature.h" |
| 15 |
#include "input/keyboard/KeyboardTranslator.h" |
| 16 |
|
| 17 |
#include <gtest/gtest.h> |
| 18 |
|
| 19 |
using namespace KODI; |
| 20 |
using namespace KEYBOARD; |
| 21 |
|
| 22 |
TEST(TestKeyboardTranslator, TranslateKeys) |
| 23 |
{ |
| 24 |
ADDON::CAddonMgr& addonManager = CServiceBroker::GetAddonMgr(); |
| 25 |
|
| 26 |
// Load add-on info |
| 27 |
ADDON::AddonPtr addon; |
| 28 |
EXPECT_TRUE(addonManager.GetAddon(DEFAULT_KEYBOARD_ID, addon, ADDON::AddonType::GAME_CONTROLLER, |
| 29 |
ADDON::OnlyEnabled::CHOICE_YES)); |
| 30 |
|
| 31 |
// Convert to game controller |
| 32 |
GAME::ControllerPtr controller = std::static_pointer_cast<GAME::CController>(addon); |
| 33 |
ASSERT_NE(controller.get(), nullptr); |
| 34 |
EXPECT_EQ(controller->ID(), DEFAULT_KEYBOARD_ID); |
| 35 |
|
| 36 |
// Load controller profile |
| 37 |
EXPECT_TRUE(controller->LoadLayout()); |
| 38 |
EXPECT_EQ(controller->Features().size(), 140); |
| 39 |
|
| 40 |
// |
| 41 |
// Spec: Should translate all keyboard symbols |
| 42 |
// |
| 43 |
unsigned int count = 0; |
| 44 |
|
| 45 |
for (const GAME::CPhysicalFeature& feature : controller->Features()) |
| 46 |
{ |
| 47 |
const KEYBOARD::XBMCKey keycode = feature.Keycode(); |
| 48 |
EXPECT_NE(keycode, KEYBOARD::XBMCKey::XBMCK_UNKNOWN); |
| 49 |
|
| 50 |
const char* symbolName = CKeyboardTranslator::TranslateKeycode(keycode); |
| 51 |
EXPECT_STRNE(symbolName, ""); |
| 52 |
|
| 53 |
const KEYBOARD::XBMCKey keycode2 = CKeyboardTranslator::TranslateKeysym(symbolName); |
| 54 |
EXPECT_EQ(keycode, keycode2); |
| 55 |
|
| 56 |
++count; |
| 57 |
} |
| 58 |
|
| 59 |
EXPECT_EQ(count, 140); |
| 60 |
} |