diff --git a/src/KeyboardTranslator.h b/src/KeyboardTranslator.h index 99c71743..25b1d696 100644 --- a/src/KeyboardTranslator.h +++ b/src/KeyboardTranslator.h @@ -49,7 +49,7 @@ namespace Konsole * (Shift,Ctrl,Alt,Meta etc.) and state flags which indicate the state * which the terminal must be in for the key sequence to apply. */ -class KeyboardTranslator +class KONSOLEPRIVATE_EXPORT KeyboardTranslator { public: /** diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 22326ca4..2fbbabce 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -24,6 +24,10 @@ endif() kde4_add_unit_test(HistoryTest HistoryTest.cpp) target_link_libraries(HistoryTest ${KONSOLE_TEST_LIBS}) + +kde4_add_unit_test(KeyboardTranslatorTest KeyboardTranslatorTest.cpp) +target_link_libraries(KeyboardTranslatorTest ${KONSOLE_TEST_LIBS}) + if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") kde4_add_unit_test(PartTest PartTest.cpp) target_link_libraries(PartTest ${KDE4_KPARTS_LIBS} diff --git a/src/tests/KeyboardTranslatorTest.cpp b/src/tests/KeyboardTranslatorTest.cpp new file mode 100644 index 00000000..a94efbc8 --- /dev/null +++ b/src/tests/KeyboardTranslatorTest.cpp @@ -0,0 +1,101 @@ +/* + Copyright 2013 by Kurt Hindenburg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + +// Own +#include "KeyboardTranslatorTest.h" + +// KDE +#include + +using namespace Konsole; + +void KeyboardTranslatorTest::testEntryTextWildcards_data() +{ + // Shift = 1 + (1 << 0) = 2 + // Alt = 1 + (1 << 2) = 3 + // Control = 1 + (1 << 4) = 5 + + QTest::addColumn("text"); + QTest::addColumn("result"); + QTest::addColumn("wildcards"); + QTest::addColumn("modifiers"); // Qt::KeyboardModifers doesn't work here + + QTest::newRow("Home no wildcards no modifiers")<< QByteArray("Home") << QByteArray("Home") << false << static_cast(Qt::NoModifier); + QTest::newRow("Home no wildcards Shift modifiers")<< QByteArray("Home") << QByteArray("Home") << false << static_cast(Qt::ShiftModifier); + QTest::newRow("Home no wildcards Alt modifiers")<< QByteArray("Home") << QByteArray("Home") << false << static_cast(Qt::AltModifier); + QTest::newRow("Home no wildcards Control modifiers")<< QByteArray("Home") << QByteArray("Home") << false << static_cast(Qt::ControlModifier); + + QTest::newRow("Home yes wildcards no modifiers")<< QByteArray("Home") << QByteArray("Home") << true << static_cast(Qt::NoModifier); + QTest::newRow("Home yes wildcards Shift modifiers")<< QByteArray("Home") << QByteArray("Home") << true << static_cast(Qt::ShiftModifier); + QTest::newRow("Home yes wildcards Alt modifiers")<< QByteArray("Home") << QByteArray("Home") << true << static_cast(Qt::AltModifier); + QTest::newRow("Home yes wildcards Control modifiers")<< QByteArray("Home") << QByteArray("Home") << true << static_cast(Qt::ControlModifier); + + + // text, results: no mod, shift, alt, control + QList entry; + entry << QByteArray("E*") << QByteArray("E1") << QByteArray("E2") << QByteArray("E3") << QByteArray("E5"); + QTest::newRow("E* yes wildcards no modifiers")<< entry[0] << entry[1] << true << static_cast(Qt::NoModifier); + QTest::newRow("E* yes wildcards Shift modifiers")<< entry[0] << entry[2] << true << static_cast(Qt::ShiftModifier); + QTest::newRow("E* yes wildcards Alt modifiers")<< entry[0] << entry[3] << true << static_cast(Qt::AltModifier); + QTest::newRow("E* yes wildcards Control modifiers")<< entry[0] << entry[4] << true << static_cast(Qt::ControlModifier); + + // combinations + entry.clear();; + entry << QByteArray("E*") << QByteArray("E4") << QByteArray("E6") << QByteArray("E8") << QByteArray("E7"); + QTest::newRow("E* yes wildcards Shift+Alt modifiers")<< entry[0] << entry[1] << true << static_cast(Qt::ShiftModifier | Qt::AltModifier); + QTest::newRow("E* yes wildcards Shift+Control modifiers")<< entry[0] << entry[2] << true << static_cast(Qt::ShiftModifier | Qt::ControlModifier); + QTest::newRow("E* yes wildcards Shift+Alt+Control modifiers")<< entry[0] << entry[3] << true << static_cast(Qt::ShiftModifier | Qt::AltModifier | Qt::ControlModifier); + QTest::newRow("E* yes wildcards Alt+Control modifiers")<< entry[0] << entry[4] << true << static_cast(Qt::AltModifier | Qt::ControlModifier); + + // text, results: no mod, shift, alt, control + entry.clear();; + entry << QByteArray("\E[24;*~") << QByteArray("\E[24;1~") << QByteArray("\E[24;2~") << QByteArray("\E[24;3~") << QByteArray("\E[24;5~"); + QTest::newRow("\E[24;*~ yes wildcards no modifiers")<< entry[0] << entry[1] << true << static_cast(Qt::NoModifier); + QTest::newRow("\E[24;*~ yes wildcards Shift modifiers")<< entry[0] << entry[2] << true << static_cast(Qt::ShiftModifier); + QTest::newRow("\E[24;*~ yes wildcards Alt modifiers")<< entry[0] << entry[3] << true << static_cast(Qt::AltModifier); + QTest::newRow("\E[24;*~ yes wildcards Control modifiers")<< entry[0] << entry[4] << true << static_cast(Qt::ControlModifier); + + // combinations + entry.clear();; + entry << QByteArray("\E[24;*~") << QByteArray("\E[24;4~") << QByteArray("\E[24;6~") << QByteArray("\E[24;8~") << QByteArray("\E[24;7~"); + QTest::newRow("\E[24;*~ yes wildcards Shift+Alt modifiers")<< entry[0] << entry[1] << true << static_cast(Qt::ShiftModifier | Qt::AltModifier); + QTest::newRow("\E[24;*~ yes wildcards Shift+Control modifiers")<< entry[0] << entry[2] << true << static_cast(Qt::ShiftModifier | Qt::ControlModifier); + QTest::newRow("\E[24;*~ yes wildcards Shift+Alt+Control modifiers")<< entry[0] << entry[3] << true << static_cast(Qt::ShiftModifier | Qt::AltModifier | Qt::ControlModifier); + QTest::newRow("\E[24;*~ yes wildcards Alt+Control modifiers")<< entry[0] << entry[4] << true << static_cast(Qt::AltModifier | Qt::ControlModifier); + +} + +void KeyboardTranslatorTest::testEntryTextWildcards() +{ + QFETCH(QByteArray, text); + QFETCH(QByteArray, result); + QFETCH(bool, wildcards); + QFETCH(quint64, modifiers); + + KeyboardTranslator::Entry entry; + Qt::KeyboardModifiers keyboardModifiers = static_cast(modifiers); + entry.setText(text); + + QCOMPARE(entry.text(wildcards, keyboardModifiers), result); +} + +QTEST_KDEMAIN_CORE(KeyboardTranslatorTest) + +#include "KeyboardTranslatorTest.moc" + diff --git a/src/tests/KeyboardTranslatorTest.h b/src/tests/KeyboardTranslatorTest.h new file mode 100644 index 00000000..b29cf7a5 --- /dev/null +++ b/src/tests/KeyboardTranslatorTest.h @@ -0,0 +1,40 @@ +/* + Copyright 2013 by Kurt Hindenburg + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. +*/ + +#ifndef KEYBOARDTRANSLATORTEST_H +#define KEYBOARDTRANSLATORTEST_H + +#include "../KeyboardTranslator.h" + +namespace Konsole +{ + +class KeyboardTranslatorTest : public QObject +{ + Q_OBJECT + +private slots: + void testEntryTextWildcards(); + void testEntryTextWildcards_data(); +}; + +} + +#endif // KEYBOARDTRANSLATORTEST_H +