mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #453 Refactor Input value classes
All previous Hardware classes have been refactored and moved into the Input namespace.
This commit is contained in:
committed by
Mathew Sutcliffe
parent
41e17aa0c7
commit
63c7c6be0d
175
tests/blackmisc/testinput.cpp
Normal file
175
tests/blackmisc/testinput.cpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/* Copyright (C) 2013
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "testinput.h"
|
||||
#include "blackmisc/input/keyboardkey.h"
|
||||
#include "blackmisc/input/hotkeycombination.h"
|
||||
#include "blackmisc/input/actionhotkeylist.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Input;
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CTestInput::CTestInput(QObject *parent): QObject(parent)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
void CTestInput::keyboardKey()
|
||||
{
|
||||
CKeyboardKey key;
|
||||
QVERIFY2(key.getKey() == Key_Unknown, "Default constructed object should have unknown key");
|
||||
QVERIFY2(key.getKeyAsString() == QString(), "Default constructed object should return empty string");
|
||||
QVERIFY2(key.hasKey() == false, "Default constructed object should return false");
|
||||
|
||||
key.setKey('C');
|
||||
QVERIFY2(key.getKey() == Key_C, "CKeyboardKey::setKey(char key) failed");
|
||||
|
||||
CKeyboardKey key2(Key_5);
|
||||
QVERIFY2(key2.getKey() == Key_5, "Returned key is wrong");
|
||||
QVERIFY2(key2.getKeyAsString() == "5", "Key as string failed");
|
||||
QVERIFY2(key2.hasKey() == true, "Should return true for key != Key_Unknown");
|
||||
|
||||
CKeyboardKey key3(Key_AltRight);
|
||||
QVERIFY2(key3.isModifier(), "RightAlt is a modifier");
|
||||
|
||||
}
|
||||
|
||||
void CTestInput::hotkeyCombination()
|
||||
{
|
||||
CHotkeyCombination comb;
|
||||
comb.addKeyboardKey(Key_5);
|
||||
comb.addKeyboardKey(Key_AltLeft);
|
||||
comb.addKeyboardKey(Key_ControlLeft);
|
||||
QVERIFY2(comb.size() == 3, "Size is incorrect");
|
||||
QVERIFY2(comb.toQString() == "CtrlLeft+AltLeft+5", "String representation failed");
|
||||
|
||||
comb.replaceKey(Key_AltLeft, Key_AltRight);
|
||||
QVERIFY2(comb.size() == 3, "Size is incorrect");
|
||||
QVERIFY2(comb.toQString() == "CtrlLeft+AltRight+5", "String representation failed");
|
||||
|
||||
comb.replaceKey(Key_AltRight, CKeyboardKey());
|
||||
QVERIFY2(comb.size() == 2, "Size is incorrect");
|
||||
QVERIFY2(comb.toQString() == "CtrlLeft+5", "String representation failed");
|
||||
|
||||
comb.removeKeyboardKey(Key_5);
|
||||
QVERIFY2(comb.size() == 1, "Size is incorrect");
|
||||
QVERIFY2(comb.toQString() == "CtrlLeft", "String representation failed");
|
||||
}
|
||||
|
||||
void CTestInput::hotKeyEqual()
|
||||
{
|
||||
CHotkeyCombination comb1;
|
||||
comb1.addKeyboardKey(Key_ControlLeft);
|
||||
comb1.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey1 (CIdentifier(), comb1, "action");
|
||||
|
||||
CHotkeyCombination comb2;
|
||||
comb2.addKeyboardKey(Key_ControlLeft);
|
||||
comb2.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey2 (CIdentifier(), comb2, "action");
|
||||
QVERIFY2(actionHotkey1 == actionHotkey2, "Objects should equal");
|
||||
}
|
||||
|
||||
void CTestInput::hotKeyNonEqual()
|
||||
{
|
||||
CHotkeyCombination comb;
|
||||
comb.addKeyboardKey(Key_ControlLeft);
|
||||
comb.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey1 (CIdentifier(), comb, "action");
|
||||
|
||||
CHotkeyCombination comb2;
|
||||
comb2.addKeyboardKey(Key_ControlLeft);
|
||||
comb2.addKeyboardKey(Key_C);
|
||||
CActionHotkey actionHotkey2 (CIdentifier(), comb2, "action");
|
||||
QVERIFY2(actionHotkey1 != actionHotkey2, "Objects should not be equal");
|
||||
|
||||
CHotkeyCombination comb3;
|
||||
comb3.addKeyboardKey(Key_ShiftLeft);
|
||||
comb3.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey3 (CIdentifier(), comb2, "action");
|
||||
QVERIFY2(actionHotkey1 != actionHotkey3, "Objects should not be equal");
|
||||
|
||||
CHotkeyCombination comb4;
|
||||
comb4.addKeyboardKey(Key_ControlLeft);
|
||||
comb4.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey4 (CIdentifier(), comb2, "other_action");
|
||||
QVERIFY2(actionHotkey1 != actionHotkey4, "Objects should not be equal");
|
||||
}
|
||||
|
||||
void CTestInput::hotkeyEqualFromVariant()
|
||||
{
|
||||
CHotkeyCombination comb1;
|
||||
comb1.addKeyboardKey(Key_ControlLeft);
|
||||
comb1.addKeyboardKey(Key_C);
|
||||
CActionHotkey actionHotkey1 (CIdentifier(), comb1, "action");
|
||||
CActionHotkeyList list1;
|
||||
list1.push_back(actionHotkey1);
|
||||
|
||||
CHotkeyCombination comb2;
|
||||
comb2.addKeyboardKey(Key_ControlLeft);
|
||||
comb2.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey2 (CIdentifier(), comb2, "action");
|
||||
CActionHotkeyList list2;
|
||||
list2.push_back(actionHotkey2);
|
||||
QVERIFY2(CVariant::fromValue(list1) != CVariant::fromValue(list2), "List should not be equal");
|
||||
}
|
||||
|
||||
void CTestInput::hotkeyFindSupersetOf()
|
||||
{
|
||||
CHotkeyCombination comb1;
|
||||
comb1.addKeyboardKey(Key_ControlLeft);
|
||||
comb1.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey1 (CIdentifier(), comb1, "action");
|
||||
|
||||
CHotkeyCombination comb2;
|
||||
comb2.addKeyboardKey(Key_ControlLeft);
|
||||
CActionHotkey actionHotkey2 (CIdentifier(), comb2, "action");
|
||||
|
||||
CHotkeyCombination comb3;
|
||||
comb3.addKeyboardKey(Key_ShiftLeft);
|
||||
comb3.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey3 (CIdentifier(), comb3, "action");
|
||||
|
||||
CActionHotkeyList list1;
|
||||
list1.push_back(actionHotkey1);
|
||||
|
||||
QVERIFY2(!list1.findSupersetsOf(actionHotkey2).isEmpty(), "CTRL+F is a superset of CTRL");
|
||||
QVERIFY2(list1.findSupersetsOf(actionHotkey3).isEmpty(), "Shift+F is not a superset of CTRL");
|
||||
}
|
||||
|
||||
void CTestInput::hotkeyFindSubsetOf()
|
||||
{
|
||||
CHotkeyCombination comb1;
|
||||
comb1.addKeyboardKey(Key_ControlLeft);
|
||||
CActionHotkey actionHotkey1 (CIdentifier(), comb1, "action");
|
||||
|
||||
CHotkeyCombination comb2;
|
||||
comb2.addKeyboardKey(Key_ControlLeft);
|
||||
comb2.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey2 (CIdentifier(), comb2, "action");
|
||||
|
||||
CHotkeyCombination comb3;
|
||||
comb3.addKeyboardKey(Key_ShiftLeft);
|
||||
comb3.addKeyboardKey(Key_D);
|
||||
CActionHotkey actionHotkey3 (CIdentifier(), comb3, "action");
|
||||
|
||||
CActionHotkeyList list1;
|
||||
list1.push_back(actionHotkey1);
|
||||
|
||||
QVERIFY2(!list1.findSubsetsOf(actionHotkey2).isEmpty(), "CTRL+F is a subset of CTRL");
|
||||
QVERIFY2(list1.findSubsetsOf(actionHotkey3).isEmpty(), "Shift+F is not a subset of CTRL");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user