| 1 | /* This file is part of the dbusmenu-qt library |
| 2 | Copyright 2010 Canonical |
| 3 | Author: Aurelien Gateau <[email protected]> |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Library General Public |
| 7 | License (LGPL) as published by the Free Software Foundation; |
| 8 | either version 2 of the License, or (at your option) any later |
| 9 | version. |
| 10 | |
| 11 | This library is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | Library General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU Library General Public License |
| 17 | along with this library; see the file COPYING.LIB. If not, write to |
| 18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | // Self |
| 22 | #include "dbusmenushortcuttest.h" |
| 23 | |
| 24 | // Qt |
| 25 | #include <QtTest> |
| 26 | |
| 27 | // DBusMenuQt |
| 28 | #include <dbusmenushortcut_p.h> |
| 29 | #include <debug_p.h> |
| 30 | |
| 31 | QTEST_MAIN(DBusMenuShortcutTest) |
| 32 | |
| 33 | namespace QTest |
| 34 | { |
| 35 | template<> |
| 36 | char *toString(const DBusMenuShortcut &dmShortcut) |
| 37 | { |
| 38 | QByteArray ba = "DBusMenuShortcut("; |
| 39 | Q_FOREACH(const QStringList& tokens, dmShortcut) { |
| 40 | ba += "("; |
| 41 | ba += tokens.join("+").toUtf8(); |
| 42 | ba += ")"; |
| 43 | } |
| 44 | ba += ")"; |
| 45 | return qstrdup(ba.data()); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | DBusMenuShortcut createKeyList(const QString& txt) |
| 50 | { |
| 51 | DBusMenuShortcut lst; |
| 52 | QStringList tokens = txt.split(','); |
| 53 | Q_FOREACH(const QString& token, tokens) { |
| 54 | lst << token.split('+'); |
| 55 | } |
| 56 | return lst; |
| 57 | } |
| 58 | |
| 59 | #define ADD_ROW(ksArgs, klArgs) QTest::newRow(#ksArgs) << QKeySequence ksArgs << createKeyList(klArgs) |
| 60 | |
| 61 | void DBusMenuShortcutTest::testConverter_data() |
| 62 | { |
| 63 | QTest::addColumn<QKeySequence>("keySequence"); |
| 64 | QTest::addColumn<DBusMenuShortcut>("keyList"); |
| 65 | |
| 66 | ADD_ROW((Qt::ALT | Qt::Key_F4), "Alt+F4"); |
| 67 | ADD_ROW((Qt::CTRL | Qt::Key_S), "Control+S"); |
| 68 | ADD_ROW((Qt::CTRL | Qt::Key_X, Qt::ALT | Qt::SHIFT | Qt::Key_Q), "Control+X,Alt+Shift+Q"); |
| 69 | ADD_ROW((Qt::META | Qt::Key_E), "Super+E"); |
| 70 | ADD_ROW((Qt::CTRL | Qt::Key_Plus), "Control+plus"); |
| 71 | ADD_ROW((Qt::CTRL | Qt::Key_Minus), "Control+minus"); |
| 72 | } |
| 73 | |
| 74 | void DBusMenuShortcutTest::testConverter() |
| 75 | { |
| 76 | QFETCH(QKeySequence, keySequence); |
| 77 | QFETCH(DBusMenuShortcut, keyList); |
| 78 | |
| 79 | DBusMenuShortcut list = DBusMenuShortcut::fromKeySequence(keySequence); |
| 80 | QCOMPARE(list, keyList); |
| 81 | QKeySequence sequence = keyList.toKeySequence(); |
| 82 | QCOMPARE(sequence.toString(), keySequence.toString()); |
| 83 | } |
| 84 | |
| 85 | #include "dbusmenushortcuttest.moc" |