File indexing completed on 2021-12-21 13:19:39

0001 /* This file is part of the dbusmenu-qt library
0002    Copyright 2010 Canonical
0003    Author: Aurelien Gateau <aurelien.gateau@canonical.com>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License (LGPL) as published by the Free Software Foundation;
0008    either version 2 of the License, or (at your option) any later
0009    version.
0010 
0011    This library is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014    Library General Public License for more details.
0015 
0016    You should have received a copy of the GNU Library General Public License
0017    along with this library; see the file COPYING.LIB.  If not, write to
0018    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0019    Boston, MA 02110-1301, USA.
0020 */
0021 // Self
0022 #include "dbusmenushortcuttest.h"
0023 
0024 // Qt
0025 #include <QtTest>
0026 
0027 // DBusMenuQt
0028 #include <dbusmenushortcut_p.h>
0029 #include <debug_p.h>
0030 
0031 QTEST_MAIN(DBusMenuShortcutTest)
0032 
0033 namespace QTest
0034 {
0035 template<>
0036 char *toString(const DBusMenuShortcut &dmShortcut)
0037 {
0038     QByteArray ba = "DBusMenuShortcut(";
0039     Q_FOREACH(const QStringList& tokens, dmShortcut) {
0040         ba += "(";
0041         ba += tokens.join("+").toUtf8();
0042         ba += ")";
0043     }
0044     ba += ")";
0045     return qstrdup(ba.data());
0046 }
0047 }
0048 
0049 DBusMenuShortcut createKeyList(const QString& txt)
0050 {
0051     DBusMenuShortcut lst;
0052     QStringList tokens = txt.split(',');
0053     Q_FOREACH(const QString& token, tokens) {
0054         lst << token.split('+');
0055     }
0056     return lst;
0057 }
0058 
0059 #define ADD_ROW(ksArgs, klArgs) QTest::newRow(#ksArgs) << QKeySequence ksArgs << createKeyList(klArgs)
0060 
0061 void DBusMenuShortcutTest::testConverter_data()
0062 {
0063     QTest::addColumn<QKeySequence>("keySequence");
0064     QTest::addColumn<DBusMenuShortcut>("keyList");
0065 
0066     ADD_ROW((Qt::ALT | Qt::Key_F4), "Alt+F4");
0067     ADD_ROW((Qt::CTRL | Qt::Key_S), "Control+S");
0068     ADD_ROW((Qt::CTRL | Qt::Key_X, Qt::ALT | Qt::SHIFT | Qt::Key_Q), "Control+X,Alt+Shift+Q");
0069     ADD_ROW((Qt::META | Qt::Key_E), "Super+E");
0070     ADD_ROW((Qt::CTRL | Qt::Key_Plus), "Control+plus");
0071     ADD_ROW((Qt::CTRL | Qt::Key_Minus), "Control+minus");
0072 }
0073 
0074 void DBusMenuShortcutTest::testConverter()
0075 {
0076     QFETCH(QKeySequence, keySequence);
0077     QFETCH(DBusMenuShortcut, keyList);
0078 
0079     DBusMenuShortcut list = DBusMenuShortcut::fromKeySequence(keySequence);
0080     QCOMPARE(list, keyList);
0081     QKeySequence sequence = keyList.toKeySequence();
0082     QCOMPARE(sequence.toString(), keySequence.toString());
0083 }
0084 
0085 #include "dbusmenushortcuttest.moc"