File indexing completed on 2024-04-28 15:19:33
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2005 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "kstandardshortcuttest.h" 0008 #include <QTest> 0009 0010 QTEST_MAIN(KStandardShortcutTest) // GUI needed by KAccel 0011 0012 #include <kstandardshortcut.h> 0013 0014 #ifndef Q_OS_WIN 0015 void initLocale() 0016 { 0017 setenv("LC_ALL", "en_US.utf-8", 1); 0018 } 0019 0020 Q_CONSTRUCTOR_FUNCTION(initLocale) 0021 #endif 0022 0023 void KStandardShortcutTest::testShortcutDefault() 0024 { 0025 QCOMPARE(QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::FullScreen)), QLatin1String("Ctrl+Shift+F")); 0026 QCOMPARE(QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::BeginningOfLine)), QLatin1String("Home")); 0027 QCOMPARE(QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::EndOfLine)), QLatin1String("End")); 0028 QCOMPARE(QKeySequence::listToString(KStandardShortcut::hardcodedDefaultShortcut(KStandardShortcut::Home)), QLatin1String("Alt+Home; Home Page")); 0029 } 0030 0031 void KStandardShortcutTest::testName() 0032 { 0033 QCOMPARE(KStandardShortcut::name(KStandardShortcut::BeginningOfLine), QLatin1String("BeginningOfLine")); 0034 QCOMPARE(KStandardShortcut::name(KStandardShortcut::EndOfLine), QLatin1String("EndOfLine")); 0035 QCOMPARE(KStandardShortcut::name(KStandardShortcut::Home), QLatin1String("Home")); 0036 } 0037 0038 void KStandardShortcutTest::testLabel() 0039 { 0040 // Tests run in English, right? 0041 QCOMPARE(KStandardShortcut::label(KStandardShortcut::FindNext), QLatin1String("Find Next")); 0042 QCOMPARE(KStandardShortcut::label(KStandardShortcut::Home), QLatin1String("Home")); 0043 } 0044 0045 void KStandardShortcutTest::testShortcut() 0046 { 0047 QCOMPARE(QKeySequence::listToString(KStandardShortcut::shortcut(KStandardShortcut::ZoomIn)), QKeySequence::listToString(KStandardShortcut::zoomIn())); 0048 } 0049 0050 void KStandardShortcutTest::testFindStdAccel() 0051 { 0052 QCOMPARE(KStandardShortcut::find(QKeySequence(Qt::CTRL | Qt::Key_F)), KStandardShortcut::Find); 0053 QCOMPARE(KStandardShortcut::find(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::ALT | Qt::Key_G)), KStandardShortcut::AccelNone); 0054 } 0055 0056 void KStandardShortcutTest::testFindByName() 0057 { 0058 for (int i = KStandardShortcut::AccelNone + 1; i < KStandardShortcut::StandardShortcutCount; ++i) { 0059 #if !KCONFIGGUI_BUILD_DEPRECATED_SINCE(5, 39) 0060 // building without deprecated enumerator, so have to skip hole in values list 0061 if (i == KStandardShortcut::SaveOptions_DEPRECATED_DO_NOT_USE) { 0062 continue; 0063 } 0064 #endif 0065 const auto id = static_cast<KStandardShortcut::StandardShortcut>(i); 0066 QCOMPARE(id, KStandardShortcut::findByName(KStandardShortcut::name(id))); 0067 } 0068 } 0069 0070 #include "moc_kstandardshortcuttest.cpp"