diff --git a/src/autotests/BookMarkTest.cpp b/src/autotests/BookMarkTest.cpp index 6ab314d4..b4f9905c 100644 --- a/src/autotests/BookMarkTest.cpp +++ b/src/autotests/BookMarkTest.cpp @@ -1,83 +1,83 @@ /* Copyright 2019 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 "BookMarkTest.h" // Qt #include // KDE #include using namespace Konsole; /* This does not use Konsole's BookmarkHandler directly; it is used to * test the code copied from there and to test any changes. */ /* Test that the URL (command) does not get mangled by KBookMark's encoding */ void BookMarkTest::testBookMarkURLs_data() { - auto testData = QFINDTESTDATA(QLatin1String("data/bookmarks.xml")); + auto testData = QFINDTESTDATA(QStringLiteral("data/bookmarks.xml")); auto bookmarkManager = KBookmarkManager::managerForFile(testData, QStringLiteral("KonsoleTest")); auto groupUrlList = bookmarkManager->root().groupUrlList(); // text explaining test, correct test result QStringList bm_urls = { QStringLiteral("simple command"), QStringLiteral("ssh machine"), QStringLiteral("command with pipe (|)"), QStringLiteral("ssh machine | tee -a /var/log/system.log"), QStringLiteral("file URL w/ non ASCII part"), QStringLiteral("file:///home/user/aκόσμε"), QStringLiteral("command with double quotes"), QStringLiteral("isql-fb -u sysdba -p example \"test\""), QStringLiteral("command with single quotes"), QStringLiteral("isql-fb -u sysdba -p example 'test'") }; QTest::addColumn("text"); QTest::addColumn("result"); for (int i = 0; i < groupUrlList.size(); ++i) { auto bm_url = groupUrlList.at(i); // Current Konsole code using bm.url() // The below is new to test decoding the url/command auto bm = QUrl::fromPercentEncoding(bm_url.url().toUtf8()); QTest::newRow(bm_urls.at(i * 2).toUtf8().data())<< bm_urls.at((i * 2) +1) << bm; } } // Only test top level URLs (no folders) void BookMarkTest::testBookMarkURLs() { QFETCH(QString, text); QFETCH(QString, result); QCOMPARE(text, result); } /* * When testing more than just URLs, the below loop can be used auto bm = root.first(); int i = 0; while (!bm.isNull()) { auto bm_url = QUrl::fromPercentEncoding(bm.url().toString().toUtf8()); qWarning()<< i << ":" < 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; Q_DECLARE_METATYPE(Qt::KeyboardModifiers) 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"); QTest::newRow("Home no wildcards no modifiers")<< QByteArray("Home") << QByteArray("Home") << false << Qt::KeyboardModifiers(Qt::NoModifier); QTest::newRow("Home no wildcards Shift modifiers")<< QByteArray("Home") << QByteArray("Home") << false << Qt::KeyboardModifiers(Qt::ShiftModifier); QTest::newRow("Home no wildcards Alt modifiers")<< QByteArray("Home") << QByteArray("Home") << false << Qt::KeyboardModifiers(Qt::AltModifier); QTest::newRow("Home no wildcards Control modifiers")<< QByteArray("Home") << QByteArray("Home") << false << Qt::KeyboardModifiers(Qt::ControlModifier); QTest::newRow("Home yes wildcards no modifiers")<< QByteArray("Home") << QByteArray("Home") << true << Qt::KeyboardModifiers(Qt::NoModifier); QTest::newRow("Home yes wildcards Shift modifiers")<< QByteArray("Home") << QByteArray("Home") << true << Qt::KeyboardModifiers(Qt::ShiftModifier); QTest::newRow("Home yes wildcards Alt modifiers")<< QByteArray("Home") << QByteArray("Home") << true << Qt::KeyboardModifiers(Qt::AltModifier); QTest::newRow("Home yes wildcards Control modifiers")<< QByteArray("Home") << QByteArray("Home") << true << Qt::KeyboardModifiers(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 << Qt::KeyboardModifiers(Qt::NoModifier); QTest::newRow("E* yes wildcards Shift modifiers")<< entry[0] << entry[2] << true << Qt::KeyboardModifiers(Qt::ShiftModifier); QTest::newRow("E* yes wildcards Alt modifiers")<< entry[0] << entry[3] << true << Qt::KeyboardModifiers(Qt::AltModifier); QTest::newRow("E* yes wildcards Control modifiers")<< entry[0] << entry[4] << true << Qt::KeyboardModifiers(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 << Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::AltModifier); QTest::newRow("E* yes wildcards Shift+Control modifiers")<< entry[0] << entry[2] << true << Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::ControlModifier); QTest::newRow("E* yes wildcards Shift+Alt+Control modifiers")<< entry[0] << entry[3] << true << Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::AltModifier | Qt::ControlModifier); QTest::newRow("E* yes wildcards Alt+Control modifiers")<< entry[0] << entry[4] << true << Qt::KeyboardModifiers(Qt::AltModifier | Qt::ControlModifier); // text, results: no mod, shift, alt, control entry.clear();; entry << QByteArray("\033[24;*~") << QByteArray("\033[24;1~") << QByteArray("\033[24;2~") << QByteArray("\033[24;3~") << QByteArray("\033[24;5~"); QTest::newRow("\033[24;*~ yes wildcards no modifiers")<< entry[0] << entry[1] << true << Qt::KeyboardModifiers(Qt::NoModifier); QTest::newRow("\033[24;*~ yes wildcards Shift modifiers")<< entry[0] << entry[2] << true << Qt::KeyboardModifiers(Qt::ShiftModifier); QTest::newRow("\033[24;*~ yes wildcards Alt modifiers")<< entry[0] << entry[3] << true << Qt::KeyboardModifiers(Qt::AltModifier); QTest::newRow("\033[24;*~ yes wildcards Control modifiers")<< entry[0] << entry[4] << true << Qt::KeyboardModifiers(Qt::ControlModifier); // combinations entry.clear();; entry << QByteArray("\033[24;*~") << QByteArray("\033[24;4~") << QByteArray("\033[24;6~") << QByteArray("\033[24;8~") << QByteArray("\033[24;7~"); QTest::newRow("\033[24;*~ yes wildcards Shift+Alt modifiers")<< entry[0] << entry[1] << true << Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::AltModifier); QTest::newRow("\033[24;*~ yes wildcards Shift+Control modifiers")<< entry[0] << entry[2] << true << Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::ControlModifier); QTest::newRow("\033[24;*~ yes wildcards Shift+Alt+Control modifiers")<< entry[0] << entry[3] << true << Qt::KeyboardModifiers(Qt::ShiftModifier | Qt::AltModifier | Qt::ControlModifier); QTest::newRow("\033[24;*~ yes wildcards Alt+Control modifiers")<< entry[0] << entry[4] << true << Qt::KeyboardModifiers(Qt::AltModifier | Qt::ControlModifier); } void KeyboardTranslatorTest::testEntryTextWildcards() { QFETCH(QByteArray, text); QFETCH(QByteArray, result); QFETCH(bool, wildcards); QFETCH(Qt::KeyboardModifiers, modifiers); KeyboardTranslator::Entry entry; entry.setText(text); QCOMPARE(entry.text(wildcards, modifiers), result); } // Use FallbackKeyboardTranslator to test basic functionality void KeyboardTranslatorTest::testFallback() { auto fallback = new FallbackKeyboardTranslator(); QCOMPARE(QStringLiteral("fallback"), fallback->name()); QCOMPARE(QStringLiteral("Fallback Keyboard Translator"), fallback->description()); auto entries = fallback->entries(); QCOMPARE(1, entries.size()); auto entry = fallback->findEntry(Qt::Key_Tab, nullptr); QVERIFY(!entry.isNull()); QCOMPARE(FallbackKeyboardTranslator::Command::NoCommand, entry.command()); QCOMPARE(Qt::Key_Tab, entry.keyCode()); QCOMPARE(QByteArray("\t"), entry.text()); QCOMPARE(QByteArray("\\t"), entry.escapedText()); QCOMPARE(Qt::NoModifier, entry.modifiers()); QCOMPARE(Qt::NoModifier, entry.modifierMask()); QCOMPARE(KeyboardTranslator::NoState, entry.state()); QCOMPARE(QStringLiteral("Tab"), entry.conditionToString()); QCOMPARE(QStringLiteral("\\t"), entry.resultToString()); QVERIFY(entry.matches(Qt::Key_Tab, Qt::NoModifier, KeyboardTranslator::NoState)); QVERIFY(entry == fallback->findEntry(Qt::Key_Tab, nullptr)); } void KeyboardTranslatorTest::testHexKeys() { - QFile linuxkeytab(QFINDTESTDATA(QLatin1String("data/test.keytab"))); + QFile linuxkeytab(QFINDTESTDATA(QStringLiteral("data/test.keytab"))); QVERIFY(linuxkeytab.exists()); QVERIFY(linuxkeytab.open(QIODevice::ReadOnly)); KeyboardTranslator* translator = new KeyboardTranslator(QStringLiteral("testtranslator")); KeyboardTranslatorReader reader(&linuxkeytab); while (reader.hasNextEntry()) { translator->addEntry(reader.nextEntry()); } linuxkeytab.close(); // A worthless check ATM if (reader.parseError()) { QFAIL("Parse failure"); } QCOMPARE(QStringLiteral("testtranslator"), translator->name()); QCOMPARE(QString(), translator->description()); auto entry = translator->findEntry(Qt::Key_Backspace, nullptr); QVERIFY(!entry.isNull()); QCOMPARE(FallbackKeyboardTranslator::Command::NoCommand, entry.command()); QCOMPARE(Qt::Key_Backspace, entry.keyCode()); QCOMPARE(QByteArray("\x7F"), entry.text()); QCOMPARE(QByteArray("\\x7f"), entry.escapedText()); QCOMPARE(Qt::NoModifier, entry.modifiers()); QCOMPARE(Qt::NoModifier, entry.modifierMask()); QCOMPARE(KeyboardTranslator::NoState, entry.state()); QCOMPARE(QStringLiteral("Backspace"), entry.conditionToString()); QCOMPARE(QStringLiteral("\\x7f"), entry.resultToString()); QVERIFY(entry.matches(Qt::Key_Backspace, Qt::NoModifier, KeyboardTranslator::NoState)); QVERIFY(entry == translator->findEntry(Qt::Key_Backspace, nullptr)); entry = translator->findEntry(Qt::Key_Delete, nullptr); QVERIFY(!entry.isNull()); QCOMPARE(FallbackKeyboardTranslator::Command::NoCommand, entry.command()); QCOMPARE(Qt::Key_Delete, entry.keyCode()); QCOMPARE(QByteArray("\x08"), entry.text()); QCOMPARE(QByteArray("\\b"), entry.escapedText()); QCOMPARE(Qt::NoModifier, entry.modifiers()); QCOMPARE(Qt::NoModifier, entry.modifierMask()); QCOMPARE(KeyboardTranslator::NoState, entry.state()); QCOMPARE(QStringLiteral("Del"), entry.conditionToString()); QCOMPARE(QStringLiteral("\\b"), entry.resultToString()); QVERIFY(entry.matches(Qt::Key_Delete, Qt::NoModifier, KeyboardTranslator::NoState)); QVERIFY(!entry.matches(Qt::Key_Backspace, Qt::NoModifier, KeyboardTranslator::NoState)); QVERIFY(!(entry == translator->findEntry(Qt::Key_Backspace, nullptr))); entry = translator->findEntry(Qt::Key_Space, nullptr); QVERIFY(!entry.isNull()); QCOMPARE(FallbackKeyboardTranslator::Command::NoCommand, entry.command()); QCOMPARE(Qt::Key_Space, entry.keyCode()); QEXPECT_FAIL("", "Several keytabs use x00 as Space +Control; text() fails", Continue); QCOMPARE(QByteArray("\x00"), entry.text()); QCOMPARE(QByteArray("\\x00"), entry.escapedText()); QCOMPARE(Qt::NoModifier, entry.modifiers()); QCOMPARE(Qt::NoModifier, entry.modifierMask()); QCOMPARE(KeyboardTranslator::NoState, entry.state()); QCOMPARE(QStringLiteral("Space"), entry.conditionToString()); QCOMPARE(QStringLiteral("\\x00"), entry.resultToString()); QVERIFY(entry.matches(Qt::Key_Space, Qt::NoModifier, KeyboardTranslator::NoState)); QVERIFY(entry == translator->findEntry(Qt::Key_Space, nullptr)); QVERIFY(!entry.matches(Qt::Key_Backspace, Qt::NoModifier, KeyboardTranslator::NoState)); QVERIFY(!(entry == translator->findEntry(Qt::Key_Backspace, nullptr))); } QTEST_GUILESS_MAIN(KeyboardTranslatorTest)