From f3076372d19d60d7f4757862ea04cb4a12fff8e5 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Wed, 5 Mar 2014 21:59:28 +0100 Subject: [PATCH] Add CKeyboardKey unit tests to BlackMisc testcases refs #83 --- src/blackmisc/hwkeyboardkey.h | 9 +---- tests/blackmisc/testblackmiscmain.cpp | 4 +- tests/blackmisc/testhardware.cpp | 58 +++++++++++++++++++++++++++ tests/blackmisc/testhardware.h | 37 +++++++++++++++++ 4 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 tests/blackmisc/testhardware.cpp create mode 100644 tests/blackmisc/testhardware.h diff --git a/src/blackmisc/hwkeyboardkey.h b/src/blackmisc/hwkeyboardkey.h index d11f72d7f..5a214c068 100644 --- a/src/blackmisc/hwkeyboardkey.h +++ b/src/blackmisc/hwkeyboardkey.h @@ -195,15 +195,10 @@ namespace BlackMisc return this->m_modifier1 != ModifierNone || this->m_modifier2 != ModifierNone; } - //! \brief Modifier? - bool hasModifier() const - { - return this->m_modifier1 != ModifierNone || this->m_modifier2 != ModifierNone; - } - /*! - * \brief Do we have this Modifier? + * \brief Do we have this modifier? * \param modifier + * \return */ bool hasModifier(Modifier modifier) const { diff --git a/tests/blackmisc/testblackmiscmain.cpp b/tests/blackmisc/testblackmiscmain.cpp index fe805b2ab..c6dab2ca1 100644 --- a/tests/blackmisc/testblackmiscmain.cpp +++ b/tests/blackmisc/testblackmiscmain.cpp @@ -9,6 +9,7 @@ #include "testgeo.h" #include "testcontainers.h" #include "testvariantandmap.h" +#include "testhardware.h" #include "testblackmiscmain.h" namespace BlackMiscTest @@ -26,13 +27,14 @@ namespace BlackMiscTest CTestGeo geoTests; CTestContainers containerTests; CTestVariantAndValueMap variantAndValueMap; + CTestHardware hardwareTests; status |= QTest::qExec(&pqBaseTests, argc, argv); status |= QTest::qExec(&avBaseTests, argc, argv); status |= QTest::qExec(&vmTests, argc, argv); status |= QTest::qExec(&geoTests, argc, argv); status |= QTest::qExec(&containerTests, argc, argv); status |= QTest::qExec(&variantAndValueMap, argc, argv); - + status |= QTest::qExec(&hardwareTests, argc, argv); } return status; } diff --git a/tests/blackmisc/testhardware.cpp b/tests/blackmisc/testhardware.cpp new file mode 100644 index 000000000..afa48b3d3 --- /dev/null +++ b/tests/blackmisc/testhardware.cpp @@ -0,0 +1,58 @@ +/* Copyright (C) 2013 VATSIM Community / authors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "testhardware.h" +#include "blackmisc/hwkeyboardkey.h" + +using namespace BlackMisc::Hardware; + +namespace BlackMiscTest +{ + + /* + * Constructor + */ + CTestHardware::CTestHardware(QObject *parent): QObject(parent) + { + // void + } + + // CKeyboardKey tests + void CTestHardware::keyboardKey() + { + // Test equal operator + CKeyboardKey key = CKeyboardKey(Qt::Key_5, '5', CKeyboardKey::ModifierAltLeft, CKeyboardKey::ModifierCtrlLeft, CKeyboardKey::HotkeyPtt); + CKeyboardKey key2; + key2.setKey(Qt::Key_5); + key2.setModifier1(CKeyboardKey::ModifierAltLeft); + key2.setModifier2(CKeyboardKey::ModifierCtrlLeft); + key2.setFunction(CKeyboardKey::HotkeyPtt); + QVERIFY2(key == key2, "CKeyboardKey::operator== failed!"); + + key = CKeyboardKey(); + key.setKey(QString("A")); + QVERIFY2(key.getKey() == Qt::Key_A, "CKeyboardKey::setKey(const QString &key) failed"); + + key.setKey(QChar('B')); + QVERIFY2(key.getKey() == Qt::Key_B, "CKeyboardKey::setKey(const QChar key) failed"); + + key.setKey(Qt::Key_C); + QVERIFY2(key.getKey() == Qt::Key_C, "CKeyboardKey::setKey(const QChar &key) failed"); + + key.setKey('D'); + QVERIFY2(key.getKey() == Qt::Key_D, "CKeyboardKey::setKey(const int key) failed"); + + key = CKeyboardKey(); + QVERIFY2(key.addModifier(CKeyboardKey::ModifierAltLeft), "CKeyboardKey::addModifier() returned wrong result"); + QVERIFY2(key.numberOfModifiers() == 1, "Expected number of modifiers to be equal to 1"); + QVERIFY2(key.getModifier1() == CKeyboardKey::ModifierAltLeft, "Expected modifier to be ModifierAltLeft"); + // Add same modifier again. This should not change the status + QVERIFY2(!key.addModifier(CKeyboardKey::ModifierAltLeft), "CKeyboardKey::addModifier() returned wrong result"); + QVERIFY2(key.numberOfModifiers() == 1, "Expected number of modifiers to be equal to 1"); + QVERIFY2(key.getModifier1() == CKeyboardKey::ModifierAltLeft, "Expected modifier to be ModifierAltLeft"); + QVERIFY2(key.getModifier2() == CKeyboardKey::ModifierNone, "Expected modifier to be ModifierAltLeft"); + } + +} // namespace diff --git a/tests/blackmisc/testhardware.h b/tests/blackmisc/testhardware.h new file mode 100644 index 000000000..81d086097 --- /dev/null +++ b/tests/blackmisc/testhardware.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2013 VATSIM Community / contributors + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef BLACKMISCTEST_TESTHARDWARE_H +#define BLACKMISCTEST_TESTHARDWARE_H + +#include + + +namespace BlackMiscTest +{ + /*! + * \brief Hardware classes basic tests + */ + class CTestHardware : public QObject + { + Q_OBJECT + public: + /*! + * \brief Standard test case constructor + * \param parent + */ + explicit CTestHardware(QObject *parent = nullptr); + + signals: + + private slots: + + //! \brief CKeyboardKey basic tests + void keyboardKey(); + + }; +} // namespace BlackMiscTest + +#endif // BLACKMISCTEST_TESTHARDWARE_H