File indexing completed on 2024-04-28 16:55:42

0001 /*
0002  * SPDX-FileCopyrightText: 2022 Aleix Pol Gonzalez <aleixpol@kde.org>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #include <QTest>
0008 #include <QtTest>
0009 
0010 #include "../src/xdgshortcut.h"
0011 
0012 class XdgShortcutTest : public QObject
0013 {
0014     Q_OBJECT
0015 public:
0016     XdgShortcutTest(QObject *parent = nullptr)
0017         : QObject(parent)
0018     {
0019         QStandardPaths::setTestModeEnabled(true);
0020     }
0021 
0022 private Q_SLOTS:
0023     void initTestCase()
0024     {
0025     }
0026 
0027     void testCheckShortcut_data()
0028     {
0029         QTest::addColumn<QString>("expression");
0030         QTest::addColumn<QKeySequence>("result");
0031 
0032         QTest::newRow("a") << "a" << QKeySequence(Qt::Key_A);
0033         QTest::newRow("ctrla") << "CTRL+a" << QKeySequence(Qt::Key_A | Qt::ControlModifier);
0034         QTest::newRow("ctrlshifta") << "CTRL+SHIFT+a" << QKeySequence(Qt::Key_A | Qt::ControlModifier | Qt::ShiftModifier);
0035         QTest::newRow("ctrlaltreturn") << "CTRL+ALT+Return" << QKeySequence(Qt::Key_Return | Qt::ControlModifier | Qt::AltModifier);
0036         QTest::newRow("withweirdtoken") << "CTRL+a;Banana" << QKeySequence(Qt::Key_A | Qt::ControlModifier);
0037         QTest::newRow("justcontrol") << "Control_L" << QKeySequence(Qt::Key_Control);
0038     }
0039 
0040     void testCheckShortcut()
0041     {
0042         QFETCH(QString, expression);
0043         QFETCH(QKeySequence, result);
0044 
0045         const auto shortcut = XdgShortcut::parse(expression);
0046         QVERIFY(shortcut.has_value());
0047         QCOMPARE(*shortcut, result);
0048     }
0049 };
0050 
0051 QTEST_GUILESS_MAIN(XdgShortcutTest)
0052 
0053 #include "xdgshortcuttest.moc"